Today insus.net practice JavaScript, implement a child window from the parent window, and after the child window handles some results, assign the result to the parent window's text box. Can see the effect:
Create two ASPX pages in the site, one is pagea.aspx and the other is pageb.aspx:
In the pagea.aspx
Copy Code code 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 Code code 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 completes, next writes the pageb.aspx child page, or writes the JavaScript script first, also has two functions, one is verifies the text box only to enter the number, another is calculates the method, in the Calc () method, has the method which calls to the parent window.
Copy Code code as follows:
<script type= "Text/javascript" >
function IsNumeric (keycode) {
Return ((keycode >= && keycode <=) | | 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 pageb.aspx <body> node, pull two text boxes, one button ammonium button.
Copy Code code as follows:
Quantity <asp:textbox id= "Textboxqty" runat= "Server" onkeydown= "return IsNumeric (Event.keycode);" onpaste= "return false;" Width= "></asp:TextBox>"
* Unit Price <asp:textbox id= "Textboxprice" runat= "Server" onkeydown= "return IsNumeric (Event.keycode);" Onpaste= "return false; " Width= "></asp:TextBox>"
<asp:button id= "Button1" runat= "Server" text= "Calculate" onclientclick= "calc ()"/>
Additionally, for text box validation articles: http://www.jb51.net/article/33586.htm