HelenScott
New Member
this is a great article: http://aspnet.4guysfromrolla.com/articles/030202-1.2.aspx. However, if the form is runat=server and server side controls I cannot make it work. Any Help is greatly appreciated.<BR><BR>Thanks<BR>ScotgtBut here's one that I whipped up....If you're just trying to populate a form control with the caledar value, this'll do it, though I used a different method than in the article. YOu actually have to hit a submit button, for what it's worth.<BR><BR><%@ Page Language="VB" %><BR><BR><script runat="server"><BR> Sub Page_Load(obj As Object, e As EventArgs)<BR> If Not Page.IsPostBack Then<BR> tbStart.Text = "Please choose a date"<BR> End If<BR> End Sub<BR> <BR> Sub Do_Submit(Sender As Object, e As EventArgs)<BR> tbStart.Text = Cal1.SelectedDate<BR> End Sub<BR></script><BR><html><body> <BR> <BR><form runat="server"><BR> <asp:Calendar id="Cal1" runat="server" <BR> BackColor="White"<BR> ForeColor="Blue" /><BR> <BR> <BR> <asp:Button id="btnSubmit" text="Submit Date Selection"<BR> onClick="Do_Submit" runat="server" /><BR> <p><BR> <asp:TextBox id="tbStart" runat="server" /><BR></form><BR><BR></body></html><BR><BR>HTHThanks, however I really want the same funtionality of the original with server side controls. Let me know if this is possible.<BR><BR>Thanks<BR>ScottWhat can't you get to work with the original code? What is the error you are getting? Can you post your modified code?Unfortunately the code is at work, I will post it in the AM. However, the problem seems to be that I am trying to use a form that has runat:server because I am using server side controls. If I change the form in your code (the rest left as is) I get the same error. <BR><BR>ThanksHere is the error message after I change form to read:<BR><form name="frmCalendar" runat=server><BR><BR>Microsoft JScript runtime error: 'window.opener.frmCalendar.txtDate' is null or not an object<BR><BR>Thanks!You also need to add id="frmCalendar" to use it with server-side form inputs. Otherwise asp.net gives it an auto id which is usually something like _ct10 or something. Sorry this was not in the original article, I am going to add it when I get the chance.Thanks, but I still get same error.<BR><BR>Form = <form id="frmcalendar" name="frmCalendar" runat=server><BR>--- This is the only line that is different. Before I change this line it works perfectly.<BR><BR>Error line= window.opener.frmCalendar.txtDate.value = '3/16/2002'<BR><BR>Error = Microsoft JScript runtime error: 'window.opener.frmCalendar.txtDate' is null or not an objectI had it working fine last night at home. I will post the code when I get home tonight. Can you show me the entire page? Did you change anything with the txtDate field?Thanks! Here is the code.<BR><BR>Calendar.aspx:<BR>---------------<BR><%@ Page Language="vb" %><BR><BR><script runat="server"><BR> Private Sub Calendar1_SelectionChanged(sender As Object, e As System.EventArgs)<BR> Dim strjscript as string = "<script language=""javascript"">"<BR> strjscript = strjscript & "window.opener." & Httpcontext.Current.Request.Querystring("formname") & ".value = '" & Calendar1.SelectedDate & "';window.close();"<BR> strjscript = strjscript & "</script" & ">" 'Don't Ask, Tool Bug<BR> Literal1.text = strjscript<BR> End Sub<BR> <BR> Private Sub Calendar1_DayRender(sender As Object, e As System.Web.UI.WebControls.DayRenderEventArgs)<BR> If e.Day.Date = datetime.now().tostring("d") Then<BR> e.Cell.BackColor = System.Drawing.Color.LightGray<BR> End If<BR> End Sub<BR></script><BR><BR><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><BR><head><BR> <title>Choose a Date</title> <BR></head><BR><body leftmargin="0" topmargin="0"><BR> <form runat="server" ID="Form1"><BR> <asp:Calendar id="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" OnDayRender="Calendar1_dayrender" showtitle="true" DayNameFormat="FirstTwoLetters" SelectionMode="Day" BackColor="#ffffff" FirstDayOfWeek="Monday" BorderColor="#000000" ForeColor="#00000" Height="60" Width="120"><BR> <TitleStyle backcolor="#000080" forecolor="#ffffff" /><BR> <NextPrevStyle backcolor="#000080" forecolor="#ffffff" /><BR> <OtherMonthDayStyle forecolor="#c0c0c0" /><BR> </asp:Calendar><BR> <asp:Literal id="Literal1" runat="server"></asp:Literal><BR> </form><BR></body><BR></html><BR><BR>---------------------------------------<BR>Webform1.aspx - From that calls the calendar.<BR>--------------------------------------------------<BR><%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="WebApplication13.WebForm1"%><BR><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><BR><html><BR> <head><BR> <title>WebForm1</title><BR> <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0"><BR> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0"><BR> <meta name="vs_defaultClientScript" content="JavaScript"><BR> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"><BR> </head><BR> <body MS_POSITIONING="GridLayout"><BR><form id="frmcalendar" name="frmCalendar" runat=server ><BR> <input name="txtDate" type="text" /><BR> <a href="javascript:calendar_window=window.open('calendar.a spx?formname=frmCalendar.txtDate','calendar_window ','width=154,height=188');calendar_window.focu s()"><BR> Calendar<BR> </a> <BR></form> </body><BR></html><BR>Also try adding id="txtDate" to the text input. Then if it still does not work send the source of webform1.aspx after it is rendered by the browser.Thanks, id="txtdate" did not work. I do not understand what you mean by "send the source of webform1.aspx after it is rendered by the browser". Can you explain or send sample code?<BR><BR>thanks for all of you help! I know this is getting to be a pain.When you pull the page up in the browser, do a view source and cut and paste that data. Also, what browser are you using for this?It is IE6. Did you want me to paste the data here?<BR><BR>-----------------------<BR><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><BR><head><BR> <title>Choose a Date</title> <BR></head><BR><body leftmargin="0" topmargin="0"><BR> <form name="Form1" method="post" action="calendar.aspx?formname=frmCalendar.txtDate" id="Form1"><BR><input type="hidden" name="__EVENTTARGET" value="" /><BR><input type="hidden" name="__EVENTARGUMENT" value="" /><BR><input type="hidden" name="__VIEWSTATE" value="dDwxODg4MTYwNjIxOzs+uGJvFviMA/euNsNOsNQ2TNdRkFA=" /><BR><BR><script language="javascript"><BR><!--<BR> function __doPostBack(eventTarget, eventArgument) {<BR> var theform = document.Form1;<BR> theform.__EVENTTARGET.value = eventTarget;<BR> theform.__EVENTARGUMENT.value = eventArgument;<BR> theform.submit();<BR> }<BR>// --><BR></script><BR><BR> <table id="Calendar1" cellspacing="0" cellpadding="2" bordercolor="Black" border="0" style="color:#000000;background-color:White;border-color:Black;border-width:1px;border-style:solid;height:60px;width:120px;border-collapse:collapse;"><BR> <tr><td colspan="7" style="background-color:Navy;"><table cellspacing="0" border="0" style="color:White;width:100%;border-collapse:collapse;"><BR> <tr><td style="color:White;background-color:Navy;width:15%;"><a href="javascript:__doPostBack('Calendar1','V762')" style="color:White"><</a></td><td align="Center" style="width:70%;">March 2002</td><td align="Right" style="color:White;background-color:Navy;width:15%;"><a href="javascript:__doPostBack('Calendar1','V821')" style="color:White">></a></td></tr><BR> </table></td></tr><tr><td align="Center">Mo</td><td align="Center">Tu</td><td align="Center">We</td><td align="Center">Th</td><td align="Center">Fr</td><td align="Center">Sa</td><td align="Center">Su</td></tr><tr><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','786')" style="color:Silver">25</a></td><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','787')" style="color:Silver">26</a></td><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','788')" style="color:Silver">27</a></td><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','789')" style="color:Silver">28</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','790')" style="color:#000000">1</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','791')" style="color:#000000">2</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','792')" style="color:#000000">3</a></td></tr><tr><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','793')" style="color:#000000">4</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','794')" style="color:#000000">5</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','795')" style="color:#000000">6</a></td><td align="Center" style="background-color:LightGrey;width:14%;"><a href="javascript:__doPostBack('Calendar1','796')" style="color:#000000">7</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','797')" style="color:#000000">8</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','798')" style="color:#000000">9</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','799')" style="color:#000000">10</a></td></tr><tr><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','800')" style="color:#000000">11</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','801')" style="color:#000000">12</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','802')" style="color:#000000">13</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','803')" style="color:#000000">14</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','804')" style="color:#000000">15</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','805')" style="color:#000000">16</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','806')" style="color:#000000">17</a></td></tr><tr><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','807')" style="color:#000000">18</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','808')" style="color:#000000">19</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','809')" style="color:#000000">20</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','810')" style="color:#000000">21</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','811')" style="color:#000000">22</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','812')" style="color:#000000">23</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','813')" style="color:#000000">24</a></td></tr><tr><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','814')" style="color:#000000">25</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','815')" style="color:#000000">26</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','816')" style="color:#000000">27</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','817')" style="color:#000000">28</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','818')" style="color:#000000">29</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','819')" style="color:#000000">30</a></td><td align="Center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','820')" style="color:#000000">31</a></td></tr><tr><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','821')" style="color:Silver">1</a></td><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','822')" style="color:Silver">2</a></td><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','823')" style="color:Silver">3</a></td><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','824')" style="color:Silver">4</a></td><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','825')" style="color:Silver">5</a></td><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','826')" style="color:Silver">6</a></td><td align="Center" style="color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','827')" style="color:Silver">7</a></td></tr><BR></table><BR> <BR> </form><BR></body><BR></html><BR><BR>That does not look right. Your form is named form1, not frmCalendar. Let me send you the working code I have tonight.Thanks! I will look for it tonight.<BR>Below is the exact page that I have working with the calendar code from the article.<BR><BR><BR><%@ Page %><BR><BR><script runat="server"><BR></script><BR><BR><html><BR><head><BR></head><BR><body><BR> <form name="form2" runat="server" id="form2"><BR> <!-- Insert content here --><input name="text1" type="text" /> <a href="javascript:calendar_window=window.open('calendar.a spx?formname=form2.text1','calendar_window','width =154,height=188');calendar_window.focus()">Calendar</a> <BR> </form><BR></body><BR></html><BR>this works great. What if the text box also is runat=server? Will this work?<BR><BR>Thanks!Nevermind, I got it to work. This is awesome! Thanks! I have been trying to do this for weeks....<BR><BR>thanks again.Glad it worked for you. I think we have the longest thread of the weak.. hello. One last question I promise. It works great with an input of type text, however I cannot get it to work with a asp:textbox. I have viewed the source after the page has rendered and made sure the name of the text box is correct. Should it work with a asp:textbox?<BR><BR>Thanks<BR>(trying to make sure we keep the longest thread)Hello, <BR>It appears that the reason it will not work with an asp:textbox, is that when the page is rendered it gives the resulting input both a id and a name that match. If I give the standard input both a name and id it will not work either.<BR><BR>Thanks<BR>ScottIt should work fine, and asp:textbox should render the same way as a html textbox to the client side. Let me test it again tonight and I will post it, but the other page had both a name and id and it worked.Try this out:<BR><BR><BR><html><BR><head><BR></head><BR><body><BR> <form id="form2" name="form2" runat="server"><BR> <asp:TextBox id="text1" name="text1" runat="server"></asp:TextBox><BR> <!-- Insert content here --><a href="javascript:calendar_window=window.open('calendar.a spx?formname=form2.text1','calendar_window','width =154,height=188');calendar_window.focus()">Calendar</a> <BR> </form><BR></body><BR></html><BR>did this code work for you? i didnt work for me!What part of the code did not work for you?I was able to get it to work. However in another way. I will post the code in the AM.<BR><BR>iam having the code with the <asp:Textbox> in a .ascx file and it's not working. When iam using the code and the file is .aspx it's working.<BR>Why can't i use a .ascx file for my <form> and <asp:Textbox>?<BR>(The .ascx is "included" in a .aspx file)One thing to check no matter how you are using this is to make sure smartnavigation is false. If it is true an error is returned saying the textbox1 is null.Hi,<BR><BR>First, congratulations to all on the length of the thread. <BR><BR>My problem is that the asp:TextBox I want to populate using the Calendar control is in a DataGrid (in fact, in the EditItemTemplate of a Template Column), and I am getting Scott’s