. Net simulates user control data persistence, Ispostback, and

Source: Internet
Author: User

Steps:
1. First, use StringBuiler to "Draw" the required forms. Here, use StringBuider instead of using the + Code directly. You don't need to explain this problem.
2. dynamically splice the data in the involved text box ------ implement data persistence of user control
3. Add a hidden field to the form to indicate whether it is a sending-back process.
Use a simple code to sum two numbers.
 
Public class jsqHandler: IHttpHandler {

Public void ProcessRequest (HttpContext context ){
Context. Response. ContentType = "text/html ";

// Declare three Integer Variables
Int n1 = 0, n2 = 0, result = 0;
Bool ispostback = Convert. ToBoolean (context. Request. Form ["IsPostBack"]);
If (! Ispostback) // determine whether to load IsPostBack in aspx. cs for the first time.
{
// Obtain numbers 1 and 2 respectively
String sn1 = context. Request. Form ["txtNum1"];
String sn2 = context. Request. Form ["txtNum2"];
If (int. TryParse (sn1, out n1) & int. TryParse (sn2, out n2 ))
{
Result = n1 + n2;
}
Context. Response. Write (result. ToString ());
}
// Draw a form with a hidden field used to determine whether the process is sending back.
StringBuilder sbHtml = new StringBuilder ();
SbHtml. Append (". Append ("<input type = 'text' name = 'txtnum1 'value = '" + n1.ToString () + "'/> ")
. Append ("+ <input type = 'text' name = 'txtnum2 'value = '" + n2.ToString () + "'/> ")
. Append ("= <input type = 'text' name = 'txtresult 'value = '" + result. ToString () + "'/> ")
. Append ("<input type = 'ddd' name = 'ispostback' value = 'false'/> ")
. Append ("<br/> <input type = 'submit 'value = 'compute'/> ")
. Append ("</form> </body> ");
Context. Response. Write (sbHtml );
}
 
Public bool IsReusable {
Get {
Return false;
}
}


From wlitsoft
 

Related Article

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.