Today, Insus. NET exercises JavaScript to open a child window from the parent window. After processing some results in the Child window, the results are assigned to the text box in the parent window. Visible effect:
Create two aspx pages on the site. One is PageA. aspx and the other is PageB. aspx:
In the Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function popUp (url ){
ObjSubWin = window. open (url, "Popup", "toolbar = no, scrollbars = no, location = no, statusbar = no, menubar = no, resizable = 0, width = 300, height = 80 ");
ObjSubWin. focus ();
}
Function SetValue (val ){
Var amount = document. getElementById ('<% = TextBoxAmount. ClientID %> ');
Amount. value = val;
}
</Script>
Then, in the <body> node, pull a TextBox and a Button:
Copy codeThe Code is as follows:
Amount:
<Asp: TextBox ID = "TextBoxAmount" runat = "server" Enabled = "false"> </asp: TextBox>
<Asp: Button ID = "Button1" runat = "server" Text = "Call child window" OnClientClick = "popUp ('pageb. aspx ')"/>
OK. The parent page is complete. Next, write PageB. aspx subpage, or write Javascript script first, also has two functions, one is to verify that the text box can only enter numbers, the other is the calculation method, within the calc () method, there is a way to call the parent window.
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function isNumeric (keyCode ){
Return (keyCode> = 48 & keyCode <= 57) | keyCode = 8)
}
Function calc (){
If (window. opener! = Null &&! Window. opener. closed ){
Var qty = document. getElementById ('<% = TextBoxqty. ClientID %> ');
Var price = document. getElementById ('<% = TextBoxPrice. ClientID %> ');
Window. opener. SetValue (parseInt (qty. value) * parseInt (price. value ));
}
}
</Script>
In the <body> node of PageB. aspx, pull two text boxes and one Button.
Copy codeThe Code is as follows:
Quantity <asp: TextBox ID = "TextBoxqty" runat = "server" onkeydown = "return isNumeric (event. keyCode); "onpaste =" return false; "Width =" 50 "> </asp: TextBox>
* Unit price <asp: TextBox ID = "TextBoxPrice" runat = "server" onkeydown = "return isNumeric (event. keyCode); "onpaste =" return false; "Width =" 50 "> </asp: TextBox>
<Asp: Button ID = "Button1" runat = "server" Text = "Calculate" OnClientClick = "calc ()"/>
Additional article about text box verification: http://www.jb51.net/article/33586.htm