Sunday, January 12, 2014

F5 problem in Asp.net

F5 problem..asp.net
Whenever we press f5 insert query between page execution whole page execute again.
Solution for this
1) Capcha
2)Maintaining session state and viewstate
How to maintain session and view state
protected void Page_PreRender(Object sender, EventArgs e)
{
ViewState["update"] = Session["update"];
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());//to avoid problem of refresh frm Browser
}
}
protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
{
if (Session["update"].ToString() == ViewState["update"].ToString())
{
//Code
Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
}
}
if user press f5 again then the buttonclick will execute again but it will not enter in
if (Session["update"].ToString() == ViewState["update"].ToString())
bcoz now session["update"] value has change.

0 comments:

Post a Comment