ASP.net pop-up dialog box return multiple values _ practical tips

Source: Internet
Author: User
Having said so much, I may not know what I am talking about. Above, you will know. Oh.


In the picture, the name has the English and Chinese points. When the user clicks the Select button in the dialog box, it can be returned to the parent dialog box.

Here's what the code says:
It contains 3 pages
The structure is shown below:

Where the Default.aspx code is as follows:

Copy Code code as follows:

<title> Pop-up Selection window </title>
<script language= "javascript" type= "Text/javascript" ><!--

function ShowDialog (CH,EN,SRC)
{
var array=new array ();
Array[0]=document.getelementbyid (CH);
Array[1]=document.getelementbyid (en);

ShowModalDialog (Src,array, "resizable:yes;"); /src for pop-up pages, array passes past parameters.
}

--></script>
<body>
<form id= "Form1" runat= "Server" >
<table border= "1px" >
<tr>
<td> </td>
&LT;TD style= "text-align:center;" style= "text-align:center;" > Chinese </td>
&LT;TD style= "text-align:center;" style= "text-align:center;" > English </td>
<td> </td>
</tr>
<tr>
<td> name:</td>
<td><asp:textbox id= "Chtxtname" runat= "Server" ></asp:TextBox></td>
<td><asp:textbox id= "Entxtname" runat= "Server" ></asp:TextBox></td>
<td><input type= "button" id= "Btnchoicename" value= "select" onclick= "ShowDialog (' chtxtname ', ' entxtname ', ' Frame.aspx '); "/></td>
</tr>
</table>
</form>
</body>

where JavaScript pops up the Modaldialog, and the pass is an array containing the objects. This is done, and multiple values are passed at the same time.
I then used the framework to use the framework to solve the problem of the pop-up page gridview.aspx not being able to pass values and caching.
The following look frame.aspx code, also very simple, no background code, just an IFRAME
Copy Code code as follows:

<title> Framework </title>
<body>
<form id= "Form1" runat= "Server" >
<iframe id= "GridView" src= "gridview.aspx src=" gridview.aspx "style=" position:relative;width:100%; "scrolling=" No "frameborder=" 0 "onload=" document.getElementById (' GridView '). style.height= ( GRIDVIEW.DOCUMENT.BODY.SCROLLHEIGHT+20) + ' px ' ' ></iframe>
</form>
</body>

This iframe is adaptive in size. Implemented through the OnLoad event.



OK, look at the gridview.aspx page.

The code is as follows:

Copy Code code as follows:

<title>GridView</title>
<body>
<form id= "Form1" runat= "Server" >
<table>
<tr>
<td>
<asp:textbox id= "Txtchname" runat= "Server" ></asp:TextBox></td>
<td>
<asp:textbox id= "Txtenname" runat= "Server" ></asp:TextBox></td>
&LT;TD style= "width:164px" >
<asp:button id= "btnnew" runat= "Server" text= "new" onclick= "Btnnew_click"/></td>
</tr>
<tr>
&LT;TD colspan= "3" >
<asp:gridview id= "GridView1" runat= "Server" autogeneratecolumns= "False" datakeynames= "ID" onrowcancelingedit= " Gridview1_rowcancelingedit "onrowediting=" gridview1_rowediting "onrowupdating=" gridview1_rowupdating " onrowdeleting= "gridview1_rowdeleting" width= "359px" backcolor= "Lightgoldenrodyellow" bordercolor= "Tan" BorderWidth = "1px" cellpadding= "2" forecolor= "Black" gridlines= "None" onselectedindexchanging= "gridview1_selectedindexchanging ">
<Columns>
<asp:boundfield datafield= "Chname" headertext= "Chinese"/>
<asp:boundfield datafield= "Enname" headertext= "English"/>
<asp:commandfield showeditbutton= "True" >
<controlstyle width= "100px"/>
</asp:CommandField>
<asp:commandfield showselectbutton= "True"/>
<asp:commandfield showdeletebutton= "True"/>
</Columns>
<EmptyDataTemplate>
Countless sources
</EmptyDataTemplate>
<footerstyle backcolor= "Tan"/>
<pagerstyle backcolor= "Palegoldenrod" forecolor= "Darkslateblue" horizontalalign= "Center"/>
<selectedrowstyle backcolor= "Darkslateblue" forecolor= "Ghostwhite"/>
<alternatingrowstyle backcolor= "Palegoldenrod"/>
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>

In this page, you can create new, insert, delete, and update. Click Select to return, triggering the following event when a selection is clicked:

Copy Code code as follows:

protected void Gridview1_selectedindexchanging (object sender, GridViewSelectEventArgs e)
{
String chname = Gridview1.rows[e.newselectedindex]. Cells[0]. Text;
String enname = Gridview1.rows[e.newselectedindex]. CELLS[1]. Text;
Response.Write ("<:script language=\" javascript\ ">
Window.dialogarguments[0].value= ' "+ chname +" '; window.dialogarguments[1].value= ' "+ Enname +"; Window.close ();< Script> ");
}

The code above is the key to return; Window.dialogarguments is actually the array of arrays we just passed over. So it has 2 objects, and these 2 objects are the objects we want to assign. Through this sentence we can achieve our goal.

Provide the original code download: this includes the database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.