Hi Everybody,
I have one requirement, I got confused which one is good in this scenario. Please help me out of this.
I have a QueryString value, I want to use this in through out my application for this I follow the below options.
Option 1: Declare Global variable and assign QueryString value on load event of that page and use that Global Variable whenever I need.
EX:
string Id="";
protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["Id"]!=null)
Id=Request.QueryString["Id"].ToString();
if(!IsPostBack)
{
//pass that Id and do whatever I need on here.
}
}
Option 2: Store ViewState inside of IsPostBack and use that viewstate value whenever I need that.
EX:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
if(Request.QueryString["Id"]!=null)
ViewState["Id"]= Request.QueryString["Id"].ToString();
//perform my action based on Viewstate value.
}
}
In option-1, I just declare one global variable and assign value on load event and use that value whenever I need.
In option-2, I just assign querystring value at once and store it into one viewstate and use that viewstate value I can implement my task.
Now, my question is when we go with Performance which option is good.