ASP.Net: How to open a second window and write something in the mainwindow?
I want to open a window on a button click (favorite is ImageButton) and开发者_JAVA技巧 do some searches there. The search should be in a grid view and give the information back directly into a textbox.
How is this possible? (best would be without javascript directly)
Client-side Option:
window.opener.document.getElementById("id").value = "whatever";
Server-side Option:
Postback your window that is open, save the data somewhere so that is retrievable by the other page, emit javascript: window.opener.submit();self.close();
on it's postback to cause your other page to then postback and the open window to close. Have your code-behind retrieve the data needed and change your TextBox.
I'll put it using javascript for the image button add this at the server side
imgBtn.Attributes.Add("onclick","open_window()")
Then Add this Javascript function in the container page
function open_window()
{
var item = document.getElementById("txtShow");
var dataitem = window.open("YourPage.aspx", "dataitem",
"toolbar=no,menubar=no,scrollbars=yes");
dataitem.item = item;
}
in the window add the select function and create a custom link in the grid view
function select_item(name) {
item.value = name;
top.close();
}
GridView:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="rowID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Field" HeaderText="Test" />
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:void(0)" onclick="select_item('<%#Eval("SelectText") %>')">Select</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
精彩评论