Check whether Querystring is available or not.

Posted by Venkat | Labels: ,

Now , i am going to explain how to check Whether the Querystring is present or available or not.

For ex: I am passing id as a querystring to the page2.aspx from page1.aspx.

So on Page1.aspx


Button1_Clickevent() Response.Redirect("page2.aspx?id=1",false); Then on Page2.aspx Page2_Loadevent() If(!IsPostback) {        If(!String.ISNullOrEmpty(Request.QueryString["id"]))         {               // get the value of Querstring id , if id is not null or empty         }        else if(!String.ISNullOrEmpty(Request.QueryString["name"]))         {              // get the value of name querystring if name is not null or empty         } }   When you run the above code - ie: on Page2.aspx you can get the id Querystring value. this works fine.   
Suppose if you pass some other querystring name ex: name from the Page1.aspx the above code gives
ie: Button2_Clickevent()
         Response.Redirect("page2.aspx?name=Dotnet",false);
Error : Object Reference Exception. 

Because it first check the  if condition so in the first condition it contains id so the querystring id will not present so it leads to the Null reference exception.


to avoid this exception you have to check like this.

Page2_Loadevent()
If(!IsPostback) {   if(Request.QueryString["id"] != null)     {        If(!String.ISNullOrEmpty(Request.QueryString["id"]))         {               // get the value of Querstring id , if id is not null or empty         }   } if ((Request.QueryString["name"] != null)   {         if(!String.ISNullOrEmpty(Request.QueryString["name"]))         {              // get the value of name querystring if name is not null or empty         } }  }
          This if(Request.QueryString["id"] != null)  - checks if id is a QueryString variable.

  If(!String.ISNullOrEmpty(Request.QueryString["id"]))  - Check if the id is empty or not

     

Setting Autocomplete Off for the Textbox

Posted by Venkat | Labels:

Now i have to show how to set the Autocompletetype - off for the asp.net  - Texbox

If you want to set the autoComplete property  off use AutoComplete="off" for the textbox.

ie: Autocomplete in the sense if the user typed some text on the textbox, then once again he entered the some word starting with the same letter, it shows previos typed word shows like a combobox manner.

To avoid showing that previous typed word by setting the autoComplete ="Off" to the Textbox.

if you want to set it for the whole page set it on the Form tag


<form autocomplete="off" id="form1" runat="server">
</form>

PayOffers.in