473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How to reference and populate controls on Content Page

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
4 2971
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tomk | last post by:
I would like to make a routine that I can reuse on all my web forms to loop thru all webcontrols. However to do this I will need to pass a reference of the class that is associated with the form...
9
by: Moe Sizlak | last post by:
Hi There, I am trying to write the selected value of a listcontrol when a button is clicked and I keep getting the error "object not set to a reference of an object". The libox itself is in a...
7
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb --...
0
by: Abraham Andres Luna | last post by:
i have a master page: <%@ Master Language="C#" %> <html> <head> <title>CRM - RDK Truck Sales & Service</title> </head> <body> <form runat="server"> <asp:contentplaceholder...
5
by: John A Grandy | last post by:
is it possible to write a vb.net code (intended to run on the client-side) that would invoke an instance of IE, have it download a page from a certain URL, and then pre-populate some of the...
4
by: bruno | last post by:
A basic question: In a content page I access a TextBox from code behind with no problems (something like Me.MyField.Text="1"). This is the portion of aspx file : <asp:Content ID="secMessagge"...
2
by: Simon Rigby | last post by:
Hi folks, A bizarre problem I am having. I have a treeview which is bound to an XmlDataSource. The XMLDataSource.Data property is set to the result of a function that generates an XML...
1
by: rjainx | last post by:
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. here is the javascript produced: ...
3
by: =?Utf-8?B?c29uaWNt?= | last post by:
Hi, What is the best way of populating a repeater control from a SQL Database using a base class. I am trying to impliment a base class that can be used across future websites and will populate...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.