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:
- 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 ());
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:
- 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;
- }
Copy code
RunProgramIn default2.aspx, values are not closed and cannot be returned. It is important to add this line to the head:
- <Base target = "_ Self"/>
Copy code