Home
ASP.Net
SQL Server
Web designing
C# [C Sharp]
Errors and Solutions
Others
Submit Article
Rss Feed
Xml Site Map
Contact Me
QnA
About Me

Passing value from popup window to parent form's TextBox

View this article as Pdf document

Posted by amit verma on 12 Aug 2008 under ASP.Net category
Download as Pdf   

Introduction

--- .aspx of parent form ---
<script type="text/javascript">
function OpenPopup() {
window.open("popup.aspx","List","scrollbars=no,resizable=no,width=400,height=280");
return false;
}
</script>
<asp:TextBox ID="txtPopupValue" runat="server" Width="327px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Show List" />
cs of parent.aspx if C#.net is the language
if (!IsPostBack) {
this.Button1.Attributes.Add("onclick", "javascript:return OpenPopup()");
}
<script language="javascript">
function GetRowValue(val)
{
// hardcoded value used to minimize the code.
// ControlID can instead be passed as query string to the popup window
window.opener.document.getElementById("ctl00_ContentPlaceHolder1_TextBox2").value = val;
window.close();
}
</script>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<AlternatingItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" />
</AlternatingItemTemplate>
<ItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
.Cs file
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) {
if ((e.Row.RowType == DataControlRowType.DataRow)) {
//assuming that the required value column is the second column in gridview
((Button)e.Row.FindControl("btnSelect")).Attributes.Add("onclick", "javascript:GetRowValue('" + e.Row.Cells[1].Text + "')");
}
}

<< Previous

Next >>

About the Author

I've been workin in microsoft technologies for more then 7 years and worked on Web and windows based application.I've been working on Clasic ASP,ASP.Net,C#,Javascript,HTML,SQL server and currently exploring C#3.5 and WFC.

Passing value from popup window to parent form's TextBox

Where the F are you Verma ???? Have you gone home??

Posted by Harvey on 28 Aug 2008

Enter your name

Enter your email address

Enter your comments(upto 500 chars)

Type the characters you see in the picture below.

Word Verification