How to implement a client callback instance (C #) without refreshing the new page-msdn learning notes

Source: Internet
Author: User
I often look for a variety of materials on the Internet to solve a specific problem. However, the final result is still good at msdn. Unfortunately, most of them are not in Chinese, and there are not many instance-type materials, however, msdn still requires us to study it carefully! <% @ Page Language = " C # " Autoeventwireup = " True "  
Codefile = " Clientcallback. aspx. CS " Inherits = " Clientcallback "   %>

<!Doctype HTML public "-// W3C // DTD XHTML
1.1 // en "" http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

< Html Xmlns = "Http://www.w3.org/1999/xhtml"   >
< Head Runat = "Server" >
< Script Type = "Text/JavaScript" >
Function Lookupstock ()
{
VaR LB = Document. Forms [ 0 ]. Listbox1;
VaR Product = LB. Options [lb. selectedindex]. Text
Callserver (product, "" );
}

Function Receiveserverdata (Rvalue)
{
Results. innertext = Rvalue;
}
</ Script >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Div >
< ASP: ListBox ID = "Listbox1" Runat = "Server" > </ ASP: ListBox >
< BR />
< BR />
< Button Onclick = "Lookupstock ()" > Look up stock </ Button >
< BR />
< BR />
Items in stock: < Span ID = "Results" > </ Span >
< BR />
</ Div >
</ Form >
</ Body >
</ Html > 1 Using system;
2 Using system. Data;
3 Using system. configuration;
4 Using system. collections;
5 Using system. Web;
6 Using system. Web. Security;
7 Using system. Web. UI;
8 Using system. Web. UI. webcontrols;
9 Using system. Web. UI. webcontrols. webparts;
10 Using system. Web. UI. htmlcontrols;
11
12 Public partial class clientcallback: system. Web. UI. Page,
13 System. Web. UI. icallbackeventhandler
14 {
15 Protected system. Collections. Specialized. listdictionary Catalog;
16 Protected void page_load (Object sender, eventargs E)
17 {
18 String cbreference =
19 Page. clientscript. getcallbackeventreference (this,
20 "Arg", "receiveserverdata", "context ");
21 String callbackscript;
22 Callbackscript = "function callserver (ARG, context)" +
23 "{" + Cbreference + "};";
24 Page. clientscript. registerclientscriptblock (this. GetType (),
25 "Callserver", callbackscript, true );
26
27 Catalog = new system. Collections. Specialized. listdictionary ();
28 Catalog. Add ("Monitor", 12 );
29 Catalog. Add ("laptop", 10 );
30 Catalog. Add ("keyboard", 23 );
31 Catalog. Add ("Mouse", 17 );
32
33 Listbox1.datasource = Catalog;
34 Listbox1.datatextfield = "key ";
35 Listbox1.databind ();
36 }
37
38 Public String raisecallbackevent (string eventargument)
39 {
40 String returnvalue;
41 If (catalog [eventargument] = NULL)
42 {
43 Returnvalue = "-1 ";
44 }
45 Else
46 {
47 Returnvalue = catalog [eventargument]. tostring ();
48 }
49 Return returnvalue;
50 }
51 }

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.