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 ");
}
}