Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi ,

I have set value in viewstate in one of my pages and tried to get in same page but i'm getting it as null. I also tried to get and set using session and hiddenfield , when i debugged it , the value is set but when that function complete the value becomes null.

Using !ispostback im using viewstate of username , and then i used jquery dialog and passed that textbox value in that dialog to perform some function in which im getting the viewstate but i am getting it as null.

Need help

Thanks


Following is the code :

C#
protected void Page_Load(object sender, EventArgs e){

        if (!IsPostBack && Request.Form["MethodName"] == "SendReply")
        {
            var a = Request.Form["Reply"].ToString();
            SendReply(a);
        }

        if (!IsPostBack && Request.Form.Count ==0 )
        {
            if (Request.QueryString["productId"] != null)
            {
                    //other unrequired code removed for sake of easiness

                        hdn.Value = Membership.GetUser(info.Mail).UserName;
                        //Session["usr"] = Membership.GetUser(info.Mail).UserName;

                    }
            }
        }
        else if(IsPostBack)
        {

        }
    }
private void SendReply(string a)
    {
        try
        {
            string username = Membership.GetUser().ToString();
            if (username!=null)
            {
 //this condition is not running because im getting hdn.value=""
                if (hdn.Value!=null || hdn.Value!="" )                      {                                  var aa = (string)Session["ownerid"];                                  Session.Remove("ownerid");                                                 }

            }
        }
        catch (Exception)
        {

        }
    }
Posted

Hi ,
Did you verify your page's ViewState is enabled? If so, you can test this code in a refresh project. then copy your code your code into new project.
Hope this will help you.
Cheers,
 
Share this answer
 
Comments
Gholamreza Fathpour 7-Apr-12 5:33am    
thanks boy
[no name] 8-Apr-12 6:37am    
actually there are 4 pages in which im getting same error. SHould i test them all in another project ?
Hi ,
As you know, ViewState is visible just in a defined page. In fact, its scope is a page, so it will be null in another pages.
 
Share this answer
 
Comments
[no name] 6-Apr-12 15:07pm    
Hi , its in same page code , im getting viewstate as null in the same page
Hi,
You should start with one of your page that has a minimum dependency to others.
if you find it works properly in your new project, then you can add other pages to new project.
cheers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900