How to get a calendar in a popup window using c#.net

Commodus2

Member
Joined
Mar 5, 2003
Messages
15
Hi.

I want to use a calendar in a popup window.
showModalDialog with javascript does niot work because you cannot use links in a showModalDialog.

i cannot manipulate the field that must contain a date from within the popup because i wat to use this popup several times on several different places.

how can i do this?
I have Visual Studio .net and i am fairly new to it.


thanks
 
U want to put this code on a some kind of event to popup the page that contains the calendar control.
in this code my form name = Calendar.aspx

===========================================
javascript:calendar_window=window.open(Calendar.aspx?formName=formName.NameofTheControlOnTheForm,calendar_window,width=290,height=200);calendar_window.focus()
==========================================
above code will enable you to open the form that contains the calendar control as a popup form.
then include this code to in the calendars event to populate the field

============================================
private void cldrInventory_SelectionChanged(object sender, System.EventArgs e)
{
StringBuilder strBlJscript = new StringBuilder();
strBlJscript.Append("<script language=\"javascript\">");
strBlJscript.Append("window.opener.");
strBlJscript.Append(HttpContext.Current.Request.QueryString.Get("formname"));
strBlJscript.Append(".value = ");
strBlJscript.Append(cldrInventory.SelectedDate.ToShortDateString());
strBlJscript.Append(";window.close();");
strBlJscript.Append("</script>");
//strBlJscript.Append(">"); //this done b/c of a Tool bug
Literal1.Text = strBlJscript.ToString();
}

============================================

this might seem little bit confusing but it is easy actually.
Hope this helps...

u have to include
<asp:literal id="Literal1" runat="server"></asp:literal>

in the calendar.aspx page too. Sorry...:-\
 
Ok thanks!
I was thinking of doing something like that... but didnt figure it out just yet. thanks for that!
it works.
although Im still messing with the literal.
I replaced this with a Page.RegisterStartupScript("start",strBlJscript.ToString());
it works also :)
in this way you dont need a literal.

at least.... i think i have this right

thanks again for you advice!
 
Ive created a popup control using the sample given. Im able to open the popup window with the javascript and Im able to set the Literal string once the Calendar is selected a day. Ive programmed the SelectionChanged to do this. However, once that event is triggered and the javascript created for the literal string, the calendar popup does not close and the parent form is not being populated.

Here is my parent form call:
<td><input id="button1" type="button" value="calendar" onclick="javascript:calendar_window=window.open(test.aspx?formname=form1&amp;textname=txt1,calendar_window,width=260,height=220);calendar_window.focus()">

And this is the event I have programmed in the Popup Calendar:
Private Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
Dim strjscript As String = "<script language=""javascript"">"
strjscript = strjscript & "window.opener." & HttpContext.Current.Request.QueryString("formname") & ".elements[" & HttpContext.Current.Request.QueryString("textname") & "].value = " & Calendar1.SelectedDate & ";window.close();"
strjscript = strjscript & "</script>" & ">"
Literal1.Text = strjscript
End Sub


Am I doing something wrong that I dont see ?
 
The script is placed at the same level when the page is rendering. So it is seen as text and not executed.
The thing I did, was to put in a js function in the SelectionChanged and then call it onClick of the button


// This is the ok button. put it in the form and this code in the event function
btnOk.Attributes.Add("onClick","doIt()");

hope this solves anything
 
Last edited by a moderator:
Back
Top