开发者

Error Object refrence not set to an instance if page is open for more than minutes

I had a problem with my internet explorer where when i refresh page the submit button the a page would also execute which was leading to double entry of data . for that i had to right the code for the refresh page where it wud clear the cache and session or it wud not enter last session values .

from the time i implemented this code it gives me

Object reference not set to an instance

Here is the code:

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        Session["DdlValue"] = DdlfacilityInsfindCsu.SelectedValue;
        if (!IsPostBack)
        {
            Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
            GetDdl();
            GetDdlIn();
        }
    }
    catch (Exception ex)
    {
        lblmess.Text = ex.Message.ToString();
    }
}
protected void Page_PreRender(object sender, EventArgs e)开发者_如何学Go
{
    ViewState["CheckRefresh"] = Session["CheckRefresh"]; ---- This is for avoiding double entry on page refresh page .
}

protected void btnsubmitinsuranceentryCsu_Click(object sender, EventArgs e)
{
    //if (Page.IsValid)
    //{
        try
        {
            if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
            {
                InsertDataI();
                Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
            }
        }
        catch (Exception ex)
        {
            lblmesss.Text = ex.Message.ToString();
        }
    //}           
}

can anyone help me on this?

Thanks.


Here is an example how to set/increase session timeout:

<system.web>
     <sessionState timeout="30" />
</system.web>

By default it's 20 minutes.

Here is an article on MSDN: http://msdn.microsoft.com/en-us/library/h6bb9cz9.aspx


Your session is probably expiring and giving you a NULL value since it no longer exists. Extend your session timeout in Web.config.


The solution you're using is a hack really.

"...I had a problem with my internet explorer where when i refresh page the submit button the a page would also execute which was leading to double entry of data ..."

Shouldn't you investigate the reason why the SUBMIT was being run twice?

Using session and viewstate variables to work-around a possibly bigger problem, namely your INSERT or stored procedure should check for duplicates before attempting another INSERT.

But more importantly, why is the browser firing another SUBMIT? It could be your cache is not cleared or it could be you're calling the SUBMIT in a weird way.

I would investigate those things first before using Session[] variables to hide the real problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜