The asp.net pop-up dialog box returns multiple values.

Source: Internet
Author: User

After talking so much, you may not know what I'm talking about ., You will know. Haha.


In the figure, the name can be English or Chinese. When you click the select button in the dialog box, you can return to the parent dialog box.

The Code is as follows:
There are 3 pages in total.
The structure is as follows:

The Default. aspx code is as follows:Copy codeThe Code is as follows: <Head runat = "server">
<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 indicates the pop-up page, where array Passes parameters.
}

// --> </Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Table border = "1px">
<Tr>
<Td> </td>
<Td style = "text-align: center;" style = "text-align: center;"> Chinese </td>
<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>
</Html>

Javascript pops up modaldialog and is passed to an array. The array contains objects. In this way, multiple values are passed at the same time.
Then I used the framework to solve the problem that the pop-up page GridView. aspx could not pass the value and cache.
The Code of Frame. aspx is also very simple. There is no background code, just an iframeCopy codeThe Code is as follows: <Head runat = "server">
<Title> framework </title>
</Head>
<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.doc ument. body. scrollHeight + 20) + 'px' "> </iframe>
</Form>
</Body>
</Html>

This iframe is adaptive. Implemented through the onload event.

Okay. Check the GridView. aspx page.

The Code is as follows:

Copy codeThe Code is as follows: <Head runat = "server">
<Title> GridView </title>
</Head>
<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>
<Td style = "width: 164px">
<Asp: Button ID = "btnNew" runat = "server" Text = "new" OnClick = "btnNew_Click"/> </td>
</Tr>
<Tr>
<Td colspan = "3">
<Asp: gridView ID = "GridView1" runat = "server" AutoGenerateColumns = "False" DataKeyNames = "ID" OnRowCancelingEdit = "inline" OnRowEditing = "inline" OnRowUpdating = "inline" OnRowDeleting = "inline ""Width =" 359px "BackColor =" LightGoldenrodYellow "BorderColor =" Tan "BorderWidth =" 1px "CellPadding =" 2 "ForeColor =" Black "GridLines =" None "OnSelectedIndexChanging =" unlock ">
<Columns>
<Asp: BoundField DataField = "chName" HeaderText = ""/>
<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>
No data
</EmptyDataTemplate>
<FooterStyle BackColor = "Tan"/>
<PagerStyle BackColor = "PaleGoldenrod" ForeColor = "DarkSlateBlue" HorizontalAlign = "Center"/>
<SelectedRowStyle BackColor = "DarkSlateBlue" ForeColor = "GhostWhite"/>
<HeaderStyle BackColor = "Tan" Font-Bold = "True"/>
<AlternatingRowStyle BackColor = "PaleGoldenrod"/>
</Asp: GridView>
</Td>
</Tr>
</Table>
</Form>
</Body>
</Html>

On this page, you can create, insert, delete, and update data. When you click Select, the following events are triggered:

Copy codeThe Code is 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 above code is the focus of the returned results. window. dialogArguments is actually the array we just passed in. Therefore, it has two objects. These two objects are the objects to be assigned values. Through this sentence, we can achieve our goal.

Download the original code: including the database.

Related Article

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.