Linkbutton click opens modalpopup, Browser back button leads to "Document expired"

317 Views Asked by At

I have a very sensitive unresolved bug for me. Pls look at this forums,

on asp:linkbutton click a modalPop will be opened, upon this if back button is clicked, browsers says "Document expired"

Linkbutton is added dynamically inside the gridview and the command also, on click of dynamically added linkbutton "lnkBtnBookTheSelected_Click" function will be called there i'm capturing the selected row ID.

bool CheckAvailability()
{
   //some logical code and getting data in "statusList"
   Session["Availability"] = statusList;
   gridViewAvailability_DataBound(null,null);
}

protected void gridViewAvailability_DataBound(object sender, EventArgs e)
{
   string[]  statusList = (string[])Session["Availability"];
   try
   {

        if (statusList.Length > 0)
        {
             int i = 1;
             foreach (GridViewRow row in gridViewAvailability.Rows)
             {
                 row.Cells[3].Controls.Clear();
                 if (statusList[i - 1] == "Available")
                 {
                      LinkButton lb = new LinkButton();
                      lb.Text = "Book this?";
                      lb.CommandArgument =i.ToString();            
lb.Command+=lnkBtnBookTheSelected_Click;                                                             
                      row.Cells[3].Controls.Add(lb);

             }
             else
             {
                  Label lbl = new Label();
                  lbl.Text ="Not available";
                  row.Cells[3].Controls.Add(lbl);
             }

         }
         i++;
     }

}
catch (Exception a)
{

}
}

protected void lnkBtnBookTheSelected_Click(object sender, CommandEventArgs e)
{    
     Session["SelectedID"] = e.CommandArgument.ToString();    
     lblUserMsgForPurpose.Text = "Dear " + Session["UserName"].ToString() + ", Please enter for what purpose you want to Booking";
     ModalPopupExtenderPurpose.Show();//popup for some input                   
}
1

There are 1 best solutions below

1
On

The "Document Expired" message from the browser is likely being caused by hitting back after POSTing the form (the postback on click).

I would suggest calling show on the ModalPopupExtender via Javascript, instead of doing a full postback.

<script type='text/javascript'>
   function showPopup() {
      $find('ModalPopupExtenderPurpose').show();
   }
</script>

Then, in your LinkButton tag, add onlick='showPopup();return 0;'

<asp:LinkButton runat='server' id='lnkBtnBookTheSelected' Text='Show Popup' onclick='showPopup();return 0;' />

You can manipulate any other HTML that you need to when it opens in the same javascript function.