views:

38

answers:

2

Hi,

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

+1  A: 

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

Tommy
Thanks tommy ....
SmartDev
+1  A: 

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

abatishchev
thanks i implemented it lets see how it goes .
SmartDev