Asp.net repeated submission Solution

Source: Internet
Author: User

1. The submitted content is processed on the current page to prevent the current page from being refreshed and submitted again
protected void imagebutton#click (Object sender, imageclickeventargs E)
{< br> adosql addcoment = new adosql ();
addcoment. add_input_coment (this. getnewsid (), this. textbox3.text, this. textbox1.text, this. textbox2.text);
// prevents sending back when the page is refreshed
int iresult;
int iup = 1000;
random RO = new random ();
iresult = Ro. next (iup);
string url = "read_n EWS. aspx? N_id = "+ request. querystring ["n_id"];
url = URL + "& R =" + iresult. tostring ();
response. redirect (URL);
}

2. Go to the new page and submit it again.
1. Set no cache for the page
Protected void page_load (Object sender, eventargs E)
{
// Set no cache on the page. The setting page is invalid.
Response. cache. setnostore ();
}
Protected void btn_reg_click (Object sender, eventargs E)
{
Omitted .......
Try
{
USI. persist (t );
T. Commit ();
Commonhelper. doupalert (this. Page, "successful! ");
Response. Write ("<script language = JavaScript> window. Location. href = Window. Location. href; </SCRIPT> ");
Response. Redirect ("~ /Index. aspx ");
}
Catch (exception ex)
{
T. rollback ();
Commonhelper. doupalert (this. Page, "failed! ");
}

}

2,
// Page loading
Protected void page_load (Object sender, eventargs E)
{
// When loading a page, you can set the page cache to "setnostore ()", that is, no cache.
Response. cache. setnostore ();
// The variable "issubmit" stored in the session indicates whether the submission is successful.
If (bool) session ["issubmit"])
{
// If the form data is submitted successfully, set "session [" issubmit "]" to false.
Session ["issubmit"] = false;
// Display the submitted information
Showmsg. Text = "* submitted successfully! ";
}
Else
// Otherwise (no submission or page refresh), no information is displayed
Showmsg. Text = "";
}
// Click the event button (btnok ).
Protected void btnok_click (Object sender, eventargs E)
{
If (txttitle. Text. tostring (). Trim () = "")........
Else if (txttext. Text. tostring (). Trim () = "").......
Else
{
// Submit the data to the database.
/*
String SQL = "insert into tab... values (...)";
Myconn. execquery (SQL );
*/
// After the submission is successful, set "session [" issubmit "]" to true
Session ["issubmit"] = true;
// Forcibly convert the page (not required, otherwise refresh will be submitted again and still go to this page ),
// The data submitted in the cache is released through page conversion, that is, the submitted bidding data is not saved to the cache,
// If you move back, the page cannot be displayed.
Response. Redirect ("post. aspx ");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.