Reputation: 729
iam using calender control in asp.net 2.0 as it is using master pages.. iam opening a window form content pages.. on window.close it is giving me null object as its not getting form name you help will be appreciated
code on content page:
<a onclick="openwindow();" ahref="#">
<img src="Images/calendar.gif" style="width: 20px; height: 20px" border=0/></a>
<input ID="Text1" runat="server" readonly="readOnly" type="text" />
function openwindow() {
window.open('/Calender.aspx', 'calendar_window','width=154,height=188');
}
code on opened window from content page
protected void Calender1_SelectionChanged(object sender, EventArgs e)
{
string strjscript = "<script language='javascript'>";
strjscript += "window.opener." + HttpContext.Current.Request.QueryString["formname"];
strjscript += ".value = '" + Calender1.SelectedDate.ToString("yyyy-MM-dd") + "'; window.close();";
strjscript += "</script" + ">";
Literal1.Text = strjscript;
}
protected void Calendar1_dayrender(object sender, DayRenderEventArgs e)
{
if(e.Day.Date==DateTime.Now)
{
e.Cell.BackColor = System.Drawing.Color.LightGray;
}
}
Upvotes: 0
Views: 724
Reputation: 7266
Looks like you are not following this tutorial but not exactly what it is doing.
Points to note:
1: Make sure you are naming your form
2: Pass textbox reference via querystring i.e. Calender.aspx?formname=frmCalendar.txtDate
3: Path to your calender.aspx is correct.
You are close to solution but may be you need to share your main page code as well for us.
Edit 1 Ok I see now what you are saying. Add this script block to your content page:
<script type="text/javascript">
function openwindow() {
var txtid = '<%=txtDate.ClientID %>';
var frmid = '<%=Page.Form.ClientID %>';
var qs = "formname=" + frmid + "." + txtid;
window.open('/Calendar.aspx?' + qs,'calendar_window', 'width=154,height=188');
}
</script>
Although if possible try using jquery datepicker and you can post your code and issue if you want to go that route.
Upvotes: 1