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"/>