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

Source: Internet
Author: User

In Asp.net, the B page is displayed from page A. After selecting data on page B, close and update the data to page A, which is a common method. I am not familiar with JavaScript, so after a busy afternoon, I finally got a little achievement:
The test project has two pages: default. aspx and default2.aspx. On the default. aspx page, there is a textbox1 and a button1, button1 is used to trigger default2.aspx, and textbox1 is used to receive values returned from the Child page.
Button1'sCodeAs follows:

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

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:

Protected void button#click (Object sender, eventargs E)
{
Stringbuilder S = new stringbuilder ();
S. append ("<script language = JavaScript>" + "\ n ");
S. append ("window. returnvalue = '" + this. getselectvalue () + "';" + "\ n ");
S. append ("window. Close ();" + "\ n ");
S. append ("</SCRIPT> ");
Type cstype = This. GetType ();
Clientscriptmanager cs = page. clientscript;
String csname = "ltype ";
If (! CS. isstartupscriptregistered (cstype, csname ))
CS. registerstartupscript (cstype, csname, S. tostring ());
}
Private string getselectvalue ()
{
String rvalue = "";
For (INT I = 0; I <this. checkboxlist1.items. Count; I ++)
{
If (this. checkboxlist1.items [I]. Selected)
{
If (Rvalue = "")
Rvalue + = This. checkboxlist1.items [I]. text;
Else
Rvalue + = "," + this. checkboxlist1.items [I]. text;
}
}
Return rvalue;
}

RunProgramIn default2.aspx, values are not closed and cannot be returned. Important:
Add this line to the head:

<Base target = "_ Self"/>

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.