Page.aspx:
Copy Code code as follows:
<title> Untitled Page </title>
<script type= "Text/javascript" ....
function Pop ()
... {
var result=showmodaldialog (' downs.aspx ', ' subpage ', ' dialogwidth:400px;dialogheight:300px;center:yes;help:no; Resizable:no;status:no '); Open the modal subform and get the return value
document.getElementById ("txt_id"). Value=result.split ("'") [0]; The return value is assigned to the related text box, respectively
document.getElementById ("Txt_name"). Value=result.split ("'") [1];
document.getElementById ("Txt_pwd"). Value=result.split ("'") [2];
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:textbox id= "txt_id" runat= "Server" ></asp:TextBox>
<asp:textbox id= "Txt_name" runat= "Server" ></asp:TextBox>
<asp:textbox id= "txt_pwd" runat= "Server" ></asp:TextBox>
<br/>
<asp:button id= "Btnpop" runat= "Server" text= "Popwindows"/>
</div>
</form>
</body>
Downs.aspx: Pop-up page
Copy Code code as follows:
<title> Untitled Page </title>
<script type= "Text/javascript" ....
function cc (INFOR_ID,INFOR_NAME,INFOR_PSW)//parameters are Id,name and password respectively
... {
window.returnvalue= infor_id+ "'" +infor_name+ "'" +INFOR_PSW; return value
Window.close ();
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:gridview id= "gvshow" runat= "server" backcolor= "white" bordercolor= "#CCCCCC"
Borderstyle= "None" borderwidth= "1px" cellpadding= "3"
>
<footerstyle backcolor= "White" forecolor= "#000066"/>
<rowstyle forecolor= "#000066"/>
<pagerstyle backcolor= "White" forecolor= "#000066" Horiz/>
<selectedrowstyle backcolor= "#669999" font-bold= "True" forecolor= "white"/>
</asp:GridView>
</div>
</form>
</body>
Downs.cs: Pop-up page background code:
Copy Code code as follows:
public partial class Downs:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Setbind ();
}
}
public void Setbind ()
{
String connstring = configurationmanager.connectionstrings["ConnStr"]. ToString ();
using (SqlConnection conn = new SqlConnection (connstring))
{
Conn. Open ();
String sql = "Select top Gwid,machtype,isok from Allinfor";
SqlDataAdapter ada = new SqlDataAdapter (SQL, conn);
DataSet ds = new DataSet ();
Ada. Fill (DS);
Gvshow. DataSource = ds. Tables[0];
This.gvshow.DataBind ();
}
}
protected void Gvshow_rowdatabound (object sender, GridViewRowEventArgs e)
{
if (E.row.rowtype = = Datacontrolrowtype.datarow)
{
E.row.attributes.add ("onclick", "CC" (' "+ e.row.cells[0]. Text + "', '" + e.row.cells[1]. Text + "', '" + e.row.cells[2]. Text + "')");
}
}
}
The second way:
ReturnValue is the property of the HTML window object in JavaScript, and is designed to return the values of the Windows.
The window.showModalDialog function opens an IE mode window (the modal window knows, that is, you can't manipulate the parent window when you open it, only when the mode window closes to operate), which is used to return the window value, for example:
Copy Code code as follows:
Father.html
<HTML>
<HEAD>
<meta name= "generator" content= "Microsoft Visual Studio 6.0" >
<TITLE></TITLE>
<script language= "JavaScript" >
function ShowModal () {
var ret = window.showModalDialog ("child.htm", NULL, "Dialogwidth:350px;dialogheight:350px;help:no;status:no");
if (ret) {Alert (' child window returns true! ');
}else{
Alert (' child window returns fake! ');
}
}
</script>
</HEAD>
<BODY>
<input id=button1 Type=button Value=button name=button1 onclick= "ShowModal ();" >
</BODY>
</HTML>
Copy Code code as follows:
Child.html
<HTML>
<HEAD>
<meta name= "generator" content= "Microsoft Visual Studio 6.0" >
<TITLE></TITLE>
<script language= "JavaScript" >
function trans (tag) {
if (tag==0) {
Window.returnvalue=false;
} else{
Window.returnvalue =true;
}
Window.close ();
}
</script>
</HEAD>
<BODY>
<input id=button1 Type=button value= "back to True" Name=button1 onclick= "trans (1)" >
<input id=button2 Type=button value= "return fake" Name=button2 onclick= "trans (0)" >
</BODY>
</HTML>
This enables you to transfer values from the modal window to the parent window.
This returnvalue can be a Boolean, integer value, etc. can also be a JS array, used to pass a lot of data.
The use of specific showmodaldialog, etc., can refer to MSDN.
Note that the following opener can only be used in window.open () and not above. Showmodel ... Other forms otherwise. will report undetife error ....
You can also change the values in the parent window in this way. Here's this. You can dynamically change multiple values in the parent window. Instead of simply putting one of the pop-up windows on the back of the window. Right away to the parent window.
Opener.document.getElementById (' Txt_phone '). Value = number;
Opener.document.getElementById (' hdn_id '). Value = ID;
Opener.document.getElementById (' Hdn_phone '). Value = number;
Window.close ();
Add this. We can still. Refreshing the parent window
Window.opener.location.href=window.opener.location.href
Window.opener.location.reload ()
If you also want to call methods in the parent window. You can also use the following. As follows
Opener. Function name (XXX,XXX)
However, the scope of the variable within the function is still the parent form.
This way we can call this function directly. If the function is asynchronous, then it's even more fun.
Which means we. You can send a request to the server in a child window ... After you close the child window ... Our parent window immediately sends an asynchronous request to the server. another window double request.