Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 01, 2012 04:42 PM by nmzike
May 01, 2012 02:08 PM|LINK
I have been looking at the numerous posts regarding the use of the <form> tag in Master Pages as well as their associated content pages. Nothing really fits what I have been able
to find. Any assistance would be greatly appreciated. Here is my situation.
I am using VS 2008 3.5 and coding in C#.
I have a web site that uses master pages. On one of my pages there are two text boxes. Next to each text box is a button that when clicked opens a smaller pop up window that allows
the user to look up information stored in a database. The smaller form uses a gridview listing of the information returned from the database query generated by the value the user enters into a text box on the popup form. The user clicks on the selected row
to populate text box on the opening page.
Type cstype =
"var txtValue = document.getElementById('txtZip').value;\n"
"window.opener.form1.txtOrigin.value = txtValue;\n"
+ //<--- this is where the script cannot see form1.txtOrigin
int index =
string tVal = Lst.Rows[index].Cells.Text;
txtZip.Text = tVal;
is null or not an object. I will assume that is because the <form id="form1" runat="server"> exists on the master page and not the content page.
The main form is quite busy now and there really is not any clean or neat way to add a gridview to it and skip the popup window. As a matter of fact, this process is used in a
couple of places in the web site.
If someone would be kind enough to either point out how I could effectively reference the opener form's control (txtOrigin) here or provide another method to get the selected
gridview value on the popup window into the main form's textbox control, I would be very grateful.
The popup form does not use the master page.
Thanks in Advance for any assistance or direction.
May 01, 2012 03:32 PM|LINK
When you are using master pages your controls get renamed in html, so although your server-side control is called
txtOrigin, the resulting control is called something else on the client. If you view->source you'll see this.
var txtOriginID = '<%=txtOrigin.ClientID %>';
And the js your child page creates will use that var
"var txtValue = document.getElementById(txtOriginID).value;\n" +
The alternative is for your Master page to expose the ClientID property and your child page to use it;
"var txtValue = document.getElementById('" + ((MasterType)Master).OriginClientID + "').value;\n" +
May 01, 2012 04:42 PM|LINK
AidyF, Thank you. I actually just managed to gut through this. I ran across an article. My problem was in the client's idea of what the control was called, just as you explained it here. Finally got it to work. Many thanks.