In Asp.net, select a value from the pop-up form

Source: Internet
Author: User
In Asp.net Page In the pop-up page B, select data in page B, close and update the data to page a, is a common method. I am not familiar with JavaScript, so after a busy afternoon, I finally got a certain score: Test Project There are two pages: default. ASP X and default2.aspx. On the default. aspx page, there is a textbox1 and a button1, button1 is used to trigger defa2.2.aspx, and textbox1 is used to receive values returned from the subpage. Button1's Code As follows:

    1. Stringbuilder S = new stringbuilder ();
    2. S. append ("<script language = JavaScript> ");
    3. S. append ("Var A = Window. showmodaldialog ('default2. aspx ');");
    4. S. append ("if (! = NULL )");
    5. S. append ("document. All ('textbox1'). value = ;");
    6. S. append ("</SCRIPT> ");
    7. Type cstype = This. GetType ();
    8. Clientscriptmanager cs = page. clientscript;
    9. String sname = "LT ";
    10. If (! CS. isstartupscriptregistered (cstype, sname ))
    11. CS. registerstartupscript (cstype, sname, S. tostring ());

Copy code

On the default2.aspx page, there is a checkboxlist1 and a button1. When button1 is executed, return the selected checkboxlist1 value and close the current page. The Code is as follows:

  1. Protected void button#click (Object sender, eventargs E)
  2. {
  3. Stringbuilder S = new stringbuilder ();
  4. S. append ("<script language = JavaScript>" + "\ n ");
  5. S. append ("window. returnvalue = '" + this. getselectvalue () + "';" + "\ n ");
  6. S. append ("window. Close ();" + "\ n ");
  7. S. append ("</SCRIPT> ");
  8. Type cstype = This. GetType ();
  9. Clientscriptmanager cs = page. clientscript;
  10. String csname = "ltype ";
  11. If (! CS. isstartupscriptregistered (cstype, csname ))
  12. CS. registerstartupscript (cstype, csname, S. tostring ());
  13. }
  14. Private string getselectvalue ()
  15. {
  16. String rvalue = "";
  17. For (INT I = 0; I <this. checkboxlist1.items. Count; I ++)
  18. {
  19. If (this. checkboxlist1.items [I]. Selected)
  20. {
  21. If (Rvalue = "")
  22. Rvalue + = This. checkboxlist1.items [I]. text;
  23. Else
  24. Rvalue + = "," + this. checkboxlist1.items [I]. text;
  25. }
  26. }
  27. Return rvalue;
  28. }

Copy code

RunProgramIn default2.aspx, values are not closed and cannot be returned. It is important to add this line to the head:

    1. <Base target = "_ Self"/>

Copy code

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.