Re: How to reference and populate controls on Content Page




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=txtStartDate','cal','width=250,height=225,left=270,top=180')">
<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=txtEndDate','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.IsClientScriptIncludeRegistered("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(this.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" <Mori@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C4433A38-2386-4A5C-8103-6134370168F2@xxxxxxxxxxxxxxxx
Thanks Ken: I have replaced txtEnd with
ctl00_ContentPlaceHolder1_txtEndDate
just as suggested. The javascript emitted is:

<script>window.opener.ctl00_ContentPlaceHolder1_txtEndDate.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.IsClientScriptIncludeRegistered("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(this.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" <Mori@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7E9AA5BE-FF1A-4246-A2A4-0115FFB2C6F1@xxxxxxxxxxxxxxxx
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.IsClientScriptIncludeRegistered("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(this.GetType(),
"anything", sb.ToString());
}






.



Relevant Pages

  • Re: How to access a control from subform
    ... Thanks Allen I have downloaded that popup, and will try that, but first I ... Option Compare Database ... Private Sub StartDate_click ... ' Set Date to the selected date and hide the calendar. ...
    (microsoft.public.access.formscoding)
  • Re: Calendar Control 10.0 Missing Events
    ... a text box and then the calendar should disappear. ... I put the calendar control in a popup form and passed a comma-delimited string in OpenArgs: ... Private Sub MyCalendarControl_AfterUpdate ... strSubFrm As String, ...
    (comp.databases.ms-access)
  • Re: Pop-up Window Coming back up. Message Box Problem
    ... user hits back, the script creates the popup again. ... | Public Sub ONSMsgBox(ByVal psMsg As String, ByVal psTitle As String, ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Add Time to popup calendar
    ... Calendar is Allen Browne's popup form: ... 'Public gtxtCalTarget As TextBox 'Text box to return the date from the ... Optional strTitle As String) ... Private Function SetSelected ...
    (microsoft.public.access.formscoding)
  • Re: Possible bug in Calendar
    ... Now stop the dishonest quoting and other extremely childish tricks and start discussing Java, ... My idea was of having Calendar implement a basic Date factory functionality and have non-standard calendars provide Date- or Calendar- wrapping and translation functionality, ... In other words, Date, Calendar, and LocalizedCalendar, analogously to the existing pattern of String, StringBuilder, and Collator, MessageBundle, and the other peripheral classes for localized String handling. ...
    (comp.lang.java.programmer)

Quantcast