By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,853 Members | 842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,853 IT Pros & Developers. It's quick & easy.

How to reference and populate controls on Content Page

P: n/a
I am using masterPage and I need to populate a textbox that is in a content
control with data from popup page that is not part of the master page. This
code works if no masterpage is involved. here is the javascript produced:

<script>window.opener.document.forms[0].txtEndDate.value =
'7/15/2006';self.close()</script>

I basically need to populate txtEndDate on the content page.

if
(!this.Page.ClientScript.IsClientScriptIncludeRegi stered("anything"))
{
string strDate = calDate.SelectedDate.ToShortDateString();
StringBuilder sb = new StringBuilder();
sb.Append("<script>window.opener.document.forms[0]." +
control.Value + ".value = '");
sb.Append(strDate);
sb.Append("';self.close()");
sb.Append("</script>");
string strCalScript = sb.ToString();
this.Page.ClientScript.RegisterClientScriptBlock(t his.GetType(),
"anything", sb.ToString());
}
Jul 16 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Mori,

When you use master pages, the controls take on different IDs. If you
execute the page and then do View Source in the browser, can you see the
"real" name of txtEndDate?

Depending on where it is, it could be something like:

ctl00_TextBox1

or

ctl00_ContentPlaceHolder1_TextBox1

Ken
Microsoft MVP [ASP.NET]

"Mori" <Mo**@discussions.microsoft.comwrote in message
news:7E**********************************@microsof t.com...
>I am using masterPage and I need to populate a textbox that is in a content
control with data from popup page that is not part of the master page.
This
code works if no masterpage is involved. here is the javascript produced:

<script>window.opener.document.forms[0].txtEndDate.value =
'7/15/2006';self.close()</script>

I basically need to populate txtEndDate on the content page.

if
(!this.Page.ClientScript.IsClientScriptIncludeRegi stered("anything"))
{
string strDate = calDate.SelectedDate.ToShortDateString();
StringBuilder sb = new StringBuilder();
sb.Append("<script>window.opener.document.forms[0]." +
control.Value + ".value = '");
sb.Append(strDate);
sb.Append("';self.close()");
sb.Append("</script>");
string strCalScript = sb.ToString();

this.Page.ClientScript.RegisterClientScriptBlock(t his.GetType(),
"anything", sb.ToString());
}

Jul 16 '06 #2

P: n/a
Thanks Ken: I have replaced txtEnd with ctl00_ContentPlaceHolder1_txtEndDate
just as suggested. The javascript emitted is:

<script>window.opener.ctl00_ContentPlaceHolder1_tx tEndDate.value =
'7/19/2006';self.close()</script>

The rest of the code now looks like this:
protected void Change_Date(object sender, System.EventArgs e)
{
if
(!this.Page.ClientScript.IsClientScriptIncludeRegi stered("anything"))
{
string strDate = calDate.SelectedDate.ToShortDateString();
string strEnd = "ctl00_ContentPlaceHolder1_txtEndDate";
StringBuilder sb = new StringBuilder();
sb.Append("<script>window.opener." + strEnd + ".value = '");
sb.Append(strDate);
sb.Append("';self.close()");
sb.Append("</script>");
string strCalScript = sb.ToString();
this.Page.ClientScript.RegisterClientScriptBlock(t his.GetType(),
"anything", sb.ToString());
}
}
However, the textbox is not populated and the popup form never closes.
What could be wrong?
"Ken Cox [Microsoft MVP]" wrote:
Hi Mori,

When you use master pages, the controls take on different IDs. If you
execute the page and then do View Source in the browser, can you see the
"real" name of txtEndDate?

Depending on where it is, it could be something like:

ctl00_TextBox1

or

ctl00_ContentPlaceHolder1_TextBox1

Ken
Microsoft MVP [ASP.NET]

"Mori" <Mo**@discussions.microsoft.comwrote in message
news:7E**********************************@microsof t.com...
I am using masterPage and I need to populate a textbox that is in a content
control with data from popup page that is not part of the master page.
This
code works if no masterpage is involved. here is the javascript produced:

<script>window.opener.document.forms[0].txtEndDate.value =
'7/15/2006';self.close()</script>

I basically need to populate txtEndDate on the content page.

if
(!this.Page.ClientScript.IsClientScriptIncludeRegi stered("anything"))
{
string strDate = calDate.SelectedDate.ToShortDateString();
StringBuilder sb = new StringBuilder();
sb.Append("<script>window.opener.document.forms[0]." +
control.Value + ".value = '");
sb.Append(strDate);
sb.Append("';self.close()");
sb.Append("</script>");
string strCalScript = sb.ToString();

this.Page.ClientScript.RegisterClientScriptBlock(t his.GetType(),
"anything", sb.ToString());
}


Jul 16 '06 #3

P: n/a
Hi Mori,

I think you'll have to some sample code from the pages because it isn't
clear to me how you're opening the secondary window. Also, in your script,
try using the JavaScript getElementById method to reference the textbox. The
ID value is much easier than the Name to use in ASP.NET.

Ken
Microsoft MVP [ASP.NET]

"Mori" <Mo**@discussions.microsoft.comwrote in message
news:C4**********************************@microsof t.com...
Thanks Ken: I have replaced txtEnd with
ctl00_ContentPlaceHolder1_txtEndDate
just as suggested. The javascript emitted is:

<script>window.opener.ctl00_ContentPlaceHolder1_tx tEndDate.value =
'7/19/2006';self.close()</script>

The rest of the code now looks like this:
protected void Change_Date(object sender, System.EventArgs e)
{
if
(!this.Page.ClientScript.IsClientScriptIncludeRegi stered("anything"))
{
string strDate = calDate.SelectedDate.ToShortDateString();
string strEnd = "ctl00_ContentPlaceHolder1_txtEndDate";
StringBuilder sb = new StringBuilder();
sb.Append("<script>window.opener." + strEnd + ".value = '");
sb.Append(strDate);
sb.Append("';self.close()");
sb.Append("</script>");
string strCalScript = sb.ToString();

this.Page.ClientScript.RegisterClientScriptBlock(t his.GetType(),
"anything", sb.ToString());
}
}
However, the textbox is not populated and the popup form never closes.
What could be wrong?
"Ken Cox [Microsoft MVP]" wrote:
>Hi Mori,

When you use master pages, the controls take on different IDs. If you
execute the page and then do View Source in the browser, can you see
the
"real" name of txtEndDate?

Depending on where it is, it could be something like:

ctl00_TextBox1

or

ctl00_ContentPlaceHolder1_TextBox1

Ken
Microsoft MVP [ASP.NET]

"Mori" <Mo**@discussions.microsoft.comwrote in message
news:7E**********************************@microso ft.com...
>I am using masterPage and I need to populate a textbox that is in a
content
control with data from popup page that is not part of the master page.
This
code works if no masterpage is involved. here is the javascript
produced:

<script>window.opener.document.forms[0].txtEndDate.value =
'7/15/2006';self.close()</script>

I basically need to populate txtEndDate on the content page.

if
(!this.Page.ClientScript.IsClientScriptIncludeRegi stered("anything"))
{
string strDate = calDate.SelectedDate.ToShortDateString();
StringBuilder sb = new StringBuilder();
sb.Append("<script>window.opener.document.forms[0]." +
control.Value + ".value = '");
sb.Append(strDate);
sb.Append("';self.close()");
sb.Append("</script>");
string strCalScript = sb.ToString();

this.Page.ClientScript.RegisterClientScriptBlock(t his.GetType(),
"anything", sb.ToString());
}



Jul 17 '06 #4

P: n/a

Here is all my code for anyone wishing to reproduce my situation. The popup
Calendar page does not use masterpage. Only the page that calls popup does.

I have very little code in the page that calls the calendar popup. here is
all I havein the contentPlaceHolder:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
runat="Server" >
<div>
<table>
<tr>
<td align="right">
Start Date:
</td>
<td align="left">
<asp:TextBox ID="txtStartDate" runat="server" />
</td>
<td align="center">
<a href="javascript:;"
onclick="window.open('CalPage.aspx?textbox=txtStar tDate','cal','width=250,height=225,left=270,top=18 0')">
<img src="images/calendar.gif" border="0">
</a>
</td>
</tr>
<tr>
<td align="right">
End Date:
</td>
<td align="left">
<asp:TextBox ID="txtEndDate" runat="server" />
</td>
<td align="center">
<a href="javascript:;"
onclick="window.open('CalPage.aspx?textbox=txtEndD ate','cal','width=250,height=225,left=270,top=180' )">
<img src="images/calendar.gif" border="0">
</a>
</td>
</tr>
</table>
</div>
</asp:Content>

For the CalendarPopup I have this in the aspx for the Calendar and hidden
input box:
<form id="form1" runat="server">
<div>
<asp:Calendar ID="calDate" OnSelectionChanged="Change_Date"
runat="server" />
<input type="hidden" id="control" runat="server" />
</div>
</form>

I also have this codebehind to extract the value from the input field and
respond to DateChangeEvent:

protected void Page_Load(object sender, EventArgs e)
{
control.Value = Request.QueryString["textbox"].ToString();
string strVal = control.Value;
}

and this to respond to the SelectionChange in the Calendar:
protected void Change_Date(object sender, System.EventArgs e)
{
if
(!this.Page.ClientScript.IsClientScriptIncludeRegi stered("anything"))
{
string strDate = calDate.SelectedDate.ToShortDateString();
string strEnd = "ctl00_ContentPlaceHolder1_txtEndDate";
StringBuilder sb = new StringBuilder();
sb.Append("<script>window.opener." + strEnd + ".value = '");
sb.Append(strDate);
sb.Append("';self.close()");
sb.Append("</script>");
string strCalScript = sb.ToString();
this.Page.ClientScript.RegisterClientScriptBlock(t his.GetType(),
"anything", sb.ToString());
}
}

"Ken Cox [Microsoft MVP]" wrote:
Hi Mori,

I think you'll have to some sample code from the pages because it isn't
clear to me how you're opening the secondary window. Also, in your script,
try using the JavaScript getElementById method to reference the textbox. The
ID value is much easier than the Name to use in ASP.NET.

Ken
Microsoft MVP [ASP.NET]

"Mori" <Mo**@discussions.microsoft.comwrote in message
news:C4**********************************@microsof t.com...
Thanks Ken: I have replaced txtEnd with
ctl00_ContentPlaceHolder1_txtEndDate
just as suggested. The javascript emitted is:

<script>window.opener.ctl00_ContentPlaceHolder1_tx tEndDate.value =
'7/19/2006';self.close()</script>

The rest of the code now looks like this:
protected void Change_Date(object sender, System.EventArgs e)
{
if
(!this.Page.ClientScript.IsClientScriptIncludeRegi stered("anything"))
{
string strDate = calDate.SelectedDate.ToShortDateString();
string strEnd = "ctl00_ContentPlaceHolder1_txtEndDate";
StringBuilder sb = new StringBuilder();
sb.Append("<script>window.opener." + strEnd + ".value = '");
sb.Append(strDate);
sb.Append("';self.close()");
sb.Append("</script>");
string strCalScript = sb.ToString();

this.Page.ClientScript.RegisterClientScriptBlock(t his.GetType(),
"anything", sb.ToString());
}
}
However, the textbox is not populated and the popup form never closes.
What could be wrong?
"Ken Cox [Microsoft MVP]" wrote:
Hi Mori,

When you use master pages, the controls take on different IDs. If you
execute the page and then do View Source in the browser, can you see
the
"real" name of txtEndDate?

Depending on where it is, it could be something like:

ctl00_TextBox1

or

ctl00_ContentPlaceHolder1_TextBox1

Ken
Microsoft MVP [ASP.NET]

"Mori" <Mo**@discussions.microsoft.comwrote in message
news:7E**********************************@microsof t.com...
I am using masterPage and I need to populate a textbox that is in a
content
control with data from popup page that is not part of the master page.
This
code works if no masterpage is involved. here is the javascript
produced:

<script>window.opener.document.forms[0].txtEndDate.value =
'7/15/2006';self.close()</script>

I basically need to populate txtEndDate on the content page.

if
(!this.Page.ClientScript.IsClientScriptIncludeRegi stered("anything"))
{
string strDate = calDate.SelectedDate.ToShortDateString();
StringBuilder sb = new StringBuilder();
sb.Append("<script>window.opener.document.forms[0]." +
control.Value + ".value = '");
sb.Append(strDate);
sb.Append("';self.close()");
sb.Append("</script>");
string strCalScript = sb.ToString();

this.Page.ClientScript.RegisterClientScriptBlock(t his.GetType(),
"anything", sb.ToString());
}


Jul 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.