Submission of refreshing pages in ASP. NET 2.0

Source: Internet
Author: User

 

Example 1:

Page:
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Input id = "txtmessage" value = "client:"/>
<Input onclick = "calltoserver ();" type = "button" value = "call to server"/>
Result:
<Input id = "txtresult"/>
</Div>
</Form>
</Body>

JS:
<SCRIPT type = "text/JavaScript">
Function calltoserver ()
{
VaR Param = Document. getelementbyid ("txtmessage"). Value + "dddd ";
// Var context = "client context ";
<% = Callbackscript %>
// Alert (this. calltoserver );
}

Function handleresultfromserver (result)
{
Document. getelementbyid ("txtresult"). value = result;
}
</SCRIPT>

Background code:
Public partial class _ default: system. Web. UI. Page, icallbackeventhandler
{
Private string sresult = "";

Protected void page_load (Object sender, eventargs E)
{

}

Public String callbackscript
{
Get
{
Return this. clientscript. getcallbackeventreference (this, "Param", "handleresultfromserver", null );
}
}

Public void raisecallbackevent (string eventargument)
{
This. sresult = "the client sends the [" + eventargument + "]." In ["+ datetime. Now. tostring () +"]. ";
}

Public String getcallbackresult ()
{
Return this. sresult;
}
}

Example 2:

Page + JS:
<HTML xmlns ="Http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<SCRIPT type = "text/JavaScript">
// Called by the button
Function callserver (inputcontrol, context)
{
Context. innerhtml = "loading ";
Arg = inputcontrol. value;
// Register the callback Method
<% = Clientscript. getcallbackeventreference (this, "Arg", "eseserverdata", "context") %>;
}
// The function registered in the callback method to receive returned results
Function compute eserverdata (result, context)
{
Context. innerhtml = result;
}
</SCRIPT>

</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
<Input id = "button1" type = "button" value = "Submit to label1" onclick = "callserver (textbox1, label1)"/> <br/>
<Asp: Label id = "label1" runat = "server" text = "label1:"> </ASP: Label>
</Div>
</Form>
</Body>
</Html>

Background code:
Public partial class default2: system. Web. UI. Page, icallbackeventhandler
{
Protected void page_load (Object sender, eventargs E)
{

}

Private string STR;
Public void raisecallbackevent (string eventargument)
{
// Different processing logic can be called based on different passed parameters
STR = "content returned from the server:" + eventargument;
}

Public String getcallbackresult ()
{
Return STR;
}

}

 

 

 

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.