C # client callback data code

Source: Internet
Author: User

  1. <% @ Page Language = "C #" AutoEventWireup = "true"
  2. CodeFile = "ClientCallback. aspx. cs" Inherits = "ClientCallback" %>
  3. <! DOCTYPE html PUBLIC "-// W3C // DTD XHTML
  4. 1.1 // EN "" http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd ">
  5. <Html>
  6. <Head id = "Head1" runat = "server">
  7. <Title> Client Callback Example </title>
  8. <Script type = "text/ecmascript">
  9. Function LookUpStock ()
  10. {
  11. Var lb = document. getElementById ("ListBox1 ");
  12. Var product = lb. options [lb. selectedIndex]. text;
  13. CallServer (product ,"");
  14. }
  15. Function compute eserverdata (rValue)
  16. {
  17. Document. getElementById ("ResultsSpan"). innerHTML = rValue;
  18. }
  19. </Script>
  20. </Head>
  21. <Body>
  22. <Form id = "form1" runat = "server">
  23. <Div>
  24. <Asp: ListBox ID = "ListBox1" Runat = "server"> </asp: ListBox>
  25. <Br/>
  26. <Br/>
  27. <Button type = "Button" onclick = "LookUpStock ()"> Look Up Stock </button>
  28. <Br/>
  29. <Br/>
  30. Items in stock: <span id = "ResultsSpan" runat = "server"> </span>
  31. <Br/>
  32. </Div>
  33. </Form>
  34. </Body>
  35. </Html>
  36. Using System;
  37. Using System. Data;
  38. Using System. Configuration;
  39. Using System. Collections;
  40. Using System. Web;
  41. Using System. Web. Security;
  42. Using System. Web. UI;
  43. Using System. Web. UI. WebControls;
  44. Using System. Web. UI. WebControls. WebParts;
  45. Using System. Web. UI. HtmlControls;
  46. Public partial class ClientCallback: System. Web. UI. Page,
  47. System. Web. UI. ICallbackEventHandler
  48. {
  49. Protected System. Collections. Specialized. ListDictionary catalog;
  50. Protected String returnValue;
  51. Protected void Page_Load (object sender, EventArgs e)
  52. {
  53. String cbReference =
  54. Page. ClientScript. GetCallbackEventReference (this,
  55. "Arg", "ReceiveServerData", "context ");
  56. String callbackScript;
  57. CallbackScript = "function CallServer (arg, context )"
  58. "{" CbReference ";}";
  59. Page. ClientScript. RegisterClientScriptBlock (this. GetType (),
  60. "CallServer", callbackScript, true );
  61. Catalog = new System. Collections. Specialized. ListDictionary ();
  62. Catalog. Add ("monitor", 12 );
  63. Catalog. Add ("laptop", 10 );
  64. Catalog. Add ("keyboard", 23 );
  65. Catalog. Add ("mouse", 17 );
  66. ListBox1.DataSource = catalog;
  67. ListBox1.DataTextField = "key ";
  68. ListBox1.DataBind ();
  69. }
  70. Public void RaiseCallbackEvent (String eventArgument)
  71. {
  72. If (catalog [eventArgument] = null)
  73. {
  74. ReturnValue = "-1 ";
  75. }
  76. Else
  77. {
  78. ReturnValue = catalog [eventArgument]. ToString ();
  79. }
  80. }
  81. Public String GetCallbackResult ()
  82. {
  83. Return returnValue;
  84. }
  85. }

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.