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 said:
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 said:
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 said:
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]
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());
}