Hukam
Hukam

Reputation: 11

How to access Hidden Field of Parent page from child page

In my ASP.NET main page I have one hidden field and and one button. When the user clicks the button I am showing the pop up (child page). I need to access a Hidden field while the pop up is loading. How could I access the Hidden field using c#?

Upvotes: 1

Views: 5329

Answers (2)

Cheng Chen
Cheng Chen

Reputation: 43513

This is your question:

In main page, there is a gridview, which contains a checkbox column, when a checkbox of a row is selected, add the corresponding ID to a hidden field. When user clicks the popup button, a window will be opened and the selected IDs will be passed to the new window. The question is the IDs are too long to pass in the query string.

My solution:

I think you can remove the hidden field, and remove all client scripts of your popup button.

<asp:button id="PopupButton" runat="server" Text="Click to pop up" />

Add a server event of the button, like:

void PopupButton_Onclick(object sender, EventArgs e)
{
   string IDs = CollectTheSelectedIDsInTheGridView();
   Session["IDs"] = IDs;
   string js = @"<script type='text/javascript'>
                    window.open('Child.aspx');
                </script>";
   Page.ClientScript.RegisterStartupScript(this.GetType(),"showChild",js);
}

EDIT Your data list must look like this:

<table>
<asp:Repeater ID="myData" runat="server">
  <ItemTemplate>
     <tr>
      <td><asp:CheckBox ID="selectedFlag" runat="server" Checked=<%# Eval("Checked") %> /></td>
      <td><asp:Label ID="dataText" runat="server" Text=<%# Eval("TextData") %>></asp:Label></td>
     </tr>
  </ItemTemplate>
</asp:Repeater>
</table>

Upvotes: 0

Cheng Chen
Cheng Chen

Reputation: 43513

Well, you can pass the value of the hidden field to the query string of the pop up. Something like this:

<asp:button id="ButtonInMainPage" runat="server" onclick="Popup();return false;" />
<asp:hidden id="hiddenValue" runat="server" />
<script type="text/javascript">
    function Popup()
    {  
       window.open('Child.aspx?hiddenValue='+document.getElementById('<%=hiddenValue.ClientID%>').value);
    }

In child page_load:

string hiddenValue = Request.QueryString["hiddenValue"];

What I show is simple code, you must add necessary check or other according to your project.

Upvotes: 2

Related Questions