In the JavaScript pop-up form, click the button to return the implementation of the selected data

Source: Internet
Author: User

First, the code of the parent page:
Copy codeThe Code is as follows:
<Head runat = "server">
<Title> No title page </title>
<% -- <Script type = "text/javascript">
Function openDia (){
Var returned = window. showModalDialog ("Default4.aspx? "+ (New Date (), window );
If (returned ){
Document. getElementById ("ret"). innerHTML = returned;
}
Else {
Document. getElementById ("ret"). innerHTML = "";
}
}
</Script> -- %>
<Script type = "text/javascript">
Function openDia (){
Var returned = window. showModalDialog ("Default3.aspx? "+ (New Date (), window );
If (returned ){
Document. getElementById ("tbtext"). value = returned;
}
Else {
Document. getElementById ("tbtext"). value = "";
}
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div id = "ret">
<Input id = "tbtext" type = "text" value = "" onclick = "openDia (); return false;"/>
</Div>
<Asp: Button ID = "Button1" runat = "server" Text = "Button" OnClientClick = "openDia (); return false;"/>
<Input id = "Hidden1" type = "hidden" runat = "server"/>
</Form>
</Body>
</Html>

New Data () is used to avoid the automatic cache of the showModalDialog page. As a result, the page is opened for the second time and the Data is not refreshed, this is because the showModalDialog page automatically displays the data in the cache if the URL is the same each time.
The code for defa3.3.aspx on the subpage is as follows:
Copy codeThe Code is as follows:
<Head runat = "server">
<Title> No title page </title>
<Script type = "text/javascript">
Function getSelected (data ){
Var str = data;
Window. returnValue = str. toString ();
Window. close ();
}
</Script>
<Base target = "_ self"/>
</Head>
<Body>
<Form id = "form1" runat = "server" target = "">
<Div>
<Asp: GridView ID = "GridView1" runat = "server" OnRowDataBound = "GridView1_RowDataBound">
<Columns>
<Asp: TemplateField>
<ItemTemplate>
<Asp: LinkButton id = "lnkSelect2" runat = "server" Text = "Select"> </asp: LinkButton>
</ItemTemplate>
</Asp: TemplateField>
</Columns>
</Asp: GridView>
</Div>
</Form>
</Body>
</Html>

Default3.aspx has a gridview control. After the data is bound (bound by yourself, the Code is not pasted), select the data you need.
Default3.aspx. cs:
[Code]
Protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e)
{
If (e. Row. RowType = DataControlRowType. DataRow)
{
LinkButton B = (LinkButton) e. Row. FindControl ("lnkSelect2 ");
B. Attributes. Add ("OnClick", "javascript: getSelected ('" + e. Row. Cells [1]. Text + "');");
}
}
[Html]
The <base target = "_ self"/> and <form target = ""> between In this case, we need to experience and improve it according to our own needs.

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.