[RESOLVED]passing paramters

i am beginner of asp.net..i know the basics of php..

Here i am struggle to passing paramter in url and get the passed paramter from the url .

any one can  give simple example please

Get parameter from URL - 

Request.QueryString["parameter1"];

To pass, you create a form and ‘submit’. 

http://html.net/tutorials/asp/lesson10.asp

I believe you are talking about QueryStrings.

They are the extra data at the end of a url:

http://www.mysite.com/subfolder?data1=123&data2=456&data3=789

if(!String.IsNullOrEmpty(Request.QueryString["data1"]))
{      //Access the value ("123")     
var data1out =
Request.QueryString["data1"];
}

if(!String.IsNullOrEmpty(Request.QueryString["data2"]))
{      //Access the value ("456")     
var data2out =
Request.QueryString["data2"];
}

if(!String.IsNullOrEmpty(Request.QueryString["data3"]))
{      //Access the value ("789")     
var data3out =
Request.QueryString["data3"];
}

very thank u .

now am using like below code

@{
     string t,pf,e,p,h; 
     p="inactive";
     pf= "inactive"; 
     e= "inactive";
    
     if(IsPost){
         t = Request.QueryString["id"];
         a = t.AsInt();
         if(a==1){
             p="active";   
         }
        else if(a ==2 ){
            e="active";
        }else if(a == 3){
            pf="active";
        }
     }
 
     }
i passed the varibles through <a href="ad.cshtml?id=1 > hi </a>
error showing is un assigned local varible a.

Un assingned local variable means that the variable you’re using a, is not yet initialized. This might be an issue where your t variable is empty. Null values cause this trouble in your code. 

Change your program logic to something like this, 

if(a != null) {
  // check for a null, if not a null, 
  // continue the process. 
  if(a == 1) {
    p="active";   
  } else if(a == 2) {
    e="active";
  } else if(a == 3) {
    pf="active";
  }
}

This would make sure if the value is not null or the variable has not yet been initialized, then it is not used in your program execution. 

bugs cleared thank u 

very thank u sir.

Leave a Reply