Parse method is used to parse any value to specified data type.
For example
string test = "42";
int32 Result;
Result = Int32.Parse(test);
This will work fine bt what if when you are aware about the value of string variable test.
if test="abc"....
In that case if u try to use above method, .NET will throw an exception as you are trying to convert string data to integer.
TryParse is a good method if the string you are converting to an interger is not always numeric.
if(!Int32.TryParse(test,out iResult))
{
//do something
}
he TryParse method returns a boolean to denote whether the conversion has been successfull or not, and returns the converted value through an out parameter.
**declare variable iResult of Int32.
Enjoy
Thursday, October 11, 2007
Wednesday, October 03, 2007
ASP.NET 2.0 Features: app_offline.htm
There is a simple way to bring down your ASP.NET 2.0 application. The only thing you have to do is to create simple html file called App_offline.htm and deploy it to your ASP.NET 2.0 web application root directory. The rest is handled by ASP.NET runtime internal routines.
The way app_offline.htm works is that you put the file in the root directory of the application. When ASP.NET sees it, it will shut-down the app-domain for the application (and not restart it for requests) and instead send back the contents of the App_offline.htm file in response to all new dynamic requests for the application. When you are done updating the site, just delete the file and it will come back online.
The way app_offline.htm works is that you put the file in the root directory of the application. When ASP.NET sees it, it will shut-down the app-domain for the application (and not restart it for requests) and instead send back the contents of the App_offline.htm file in response to all new dynamic requests for the application. When you are done updating the site, just delete the file and it will come back online.
Friday, September 07, 2007
Assign Value to Asp.Net TextBox with mode="Password"
ASP.NET server control doesn't want toadd/display the value in a password textbox because of security concerns.
you have to add it yourself using an attribute.
Add this following line of code when you want set the value
TextBox1.Attributes.Add("value", "thePassword")
*( TextBox1 is a password textbox.)
While given solution will work, if a user does a view source onthe form, the password is visible as plain text and that is never goodfrom a security standpoint.
Rather, I would use Viewstate to hold the password value and if the userdoesn't change it then retrieve the value from view state.
Other Scenario is:-
On most of the web sites at the time of registration password is asked.You must have noticed after submitting the page if you are again redirected to the page due to unsuccessful registration value of password field is lost.
This is due to security concerns as everything is gets rendered on the client side So when you view the source in the browser password value will be there.
But if explicitly you want to set the value of password text box again then use following method in .NET 2.0
txtPassword.Attributes["value"] = Request.Form[txtPassword.ClientID]; //in C#.Net 2.0
Enjoy
you have to add it yourself using an attribute.
Add this following line of code when you want set the value
TextBox1.Attributes.Add("value", "thePassword")
*( TextBox1 is a password textbox.)
While given solution will work, if a user does a view source onthe form, the password is visible as plain text and that is never goodfrom a security standpoint.
Rather, I would use Viewstate to hold the password value and if the userdoesn't change it then retrieve the value from view state.
Other Scenario is:-
On most of the web sites at the time of registration password is asked.You must have noticed after submitting the page if you are again redirected to the page due to unsuccessful registration value of password field is lost.
This is due to security concerns as everything is gets rendered on the client side So when you view the source in the browser password value will be there.
But if explicitly you want to set the value of password text box again then use following method in .NET 2.0
txtPassword.Attributes["value"] = Request.Form[txtPassword.ClientID]; //in C#.Net 2.0
Enjoy
Subscribe to:
Posts (Atom)