无法从同一页面中的会话和viewstate获取值 [英] unable to get value from session and viewstate in same page

查看:82
本文介绍了无法从同一页面中的会话和viewstate获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在我的一个页面中的viewstate中设置了值并尝试进入同一页但我将其设为null。我也尝试使用session和hiddenfield进行设置,当我调试它时,设置了值,但是当该函数完成时,该值变为null。



使用!ispostback即时通讯使用用户名的viewstate,然后我使用jquery对话框并在该对话框中传递该文本框值以执行一些功能,其中我获取viewstate但我得到它为null。



需要帮助



谢谢





以下是代码:



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 :

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)
        {

        }
    }

推荐答案

您好,

您是否验证了您的页面的ViewState已启用?如果是这样,您可以在刷新项目中测试此代码。然后将你的代码复制到新项目中。

希望这对你有帮助。

干杯,
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,



如您所知,ViewState只在定义的页面中可见。实际上,它的范围是一个页面,所以在其他页面中它将为null。
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.




你应该从你的一个页面开始最低限度依赖他人。

如果你发现它在新项目中正常运行,那么你可以将其他页面添加到新项目中。

欢呼。
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.


这篇关于无法从同一页面中的会话和viewstate获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆