删除按钮单击事件的会话 [英] Removing session on button click event

查看:113
本文介绍了删除按钮单击事件的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个严重的错误.我在某些页面的会话中保留了一些日期. dan在其他页面的页面加载上,我使用该会话来填充文本框,并且在texbox下载按钮下方.问题是,如果用户更改文本框中的日期,然后单击该日期的下载按钮,那么我得到的日期仍在会话中.也就是说,一旦会话填充了文本框,我将无法更改日期.尽管我正在清除会话并在按钮单击事件上将其删除,但您仍然可以告诉我wat m丢失了吗?
这是我的代码:-

Hi all,

I have a serious bug. I have some dates that i maintain in a session from some page. dan on the page load of other page i use that session to fill the text box and below the texbox download button is there. The problem is that if the user changes the date in text box and than clicks on the download button for that date still the date that i am getting is which was in session. That is I am not able to change the dates once session has filled the text box. Although I am clearing the session and removing it on button click event still... Can u plzz tell me wat m missing ?
here is my code:-

protected void btnDwnload_Click(object sender, EventArgs e)
    {
        Session["str_Single_Date"] = null;
        Session.Remove("str_Single_Date");

        Session["str_Single_Date"] = null;
        Session.Remove("str_Single_Date");

        
        string strData = txtDataType.Text;
        string strDataType = strData.ToString().ToUpperInvariant().Trim();
        DateTime From = Convert.ToDateTime(txtFrom.Text.Trim()); <--- here i m getting the same dates always
        DateTime To = Convert.ToDateTime(txtTo.Text.Trim());  <--- here i m getting the same dates always
        string strComb = txtCombi.Text;
        string strProd = txtProd.Text;
        string strHSCODE = txtHSCode.Text;
       

        int iResult = bl_Query_for_admin.Query_Data(strDataType, From, To,strHSCODE, strComb, strProd);
        if (iResult == 1)
        {
            lblMsg.Visible = false;
        }
        else
        {
            lblMsg.Visible = true;
            lblMsg.Text = "Invalid Query Formation Resulted Into No Data Generation !";
        }

    }

推荐答案

除非在
Stop loading the textbox with the dates in your Page_load event except when IsPostBack[^] is false!

When your user presses a button, your application is started, and the Page Load event handler is called. If you do not check in the handler if this is a Postback, you load the values from the Session into the TextBox, and overwrite any values the user had entered. The Button Click event handler is then called, which reads the overwritten values from the text boxes.

So what it looks like is that the session values are not being deleted - they are, but just after you have used the values to overwrite the user input!


这是删除会话的语法
Session.Remove("SessionName");

您可以通过会话值填充文本框数据
this is the syntax for removing session
Session.Remove("SessionName");

you fill the textbox data by session value
protected void Page_Load(object sender, EventArgs e)
    {

// assign textbox value to session on postback 
if (IsPostBack)
        {
            Session["SessionName"] =TextBox1.text;
        }
/*
if is not post back and open first time page then assign textbox value from session
*/

if (!IsPostBack)
{
TextBox1.text=Session["SessionName"].ToString();
}

}



如果您在上面所述的页面加载事件中执行了代码,则无需删除会话.



if you do code in page load event like i describe above than you don''t need to remove session.


有人可以帮我吗?


这篇关于删除按钮单击事件的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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