utpal Posted July 10, 2003 Posted July 10, 2003 Hi All , I have a problem with reading a Clicked Date from a Pop-Up Calendar. I have the button and a Text Box in a WebForm.Clicking this button pops up a calendar(which is a separate WebForm). Selecting a Date on the WebForm transfers the selected Date to the Text Box(on the Other WebForm). In the "Code Behind" for the Calendar WebForm I have the following Code:: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here 'THE FOLLOWING LINE GIVES ME AN ERROR -- IT SAYS THAT 'System.NullReferenceException: Object reference not set to an instance of an object. Hidden1.Value = Request.QueryString("textbox").ToString() End Sub Public Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Dim strScript As String = "<script>window.opener.document.forms(0)." + Hidden1.Value + ".value = '" strScript += Calendar1.SelectedDate.ToString("MM/dd/yyyy") strScript += "';self.close()" strScript += "</" + "script>" RegisterClientScriptBlock("anything", strScript) End Sub iN THE paGE WHERE THE BUTTON IS CLICKED I HAVE THE FOLLOWING CODE IN THE html PART <INPUT name="textBox1" type="text" id="textbox1"> <INPUT type="button" runat="server" onclick="javascript:cal=window.open('Calender.aspx?textbox = textbox1','cal','width=800,height=800' );cal.setfocus()" value="Button" /> nOW WHAT IS THE WAY OUT? HELP IS GREATLY APPRECIATED.tHANKS , Quote
WebJumper Posted July 10, 2003 Posted July 10, 2003 First of all, what you are creating is not a Popup, it's just a new window! A Popup appears on the asp/html page - no new window! For your html code, the Button needs no runat="server" <INPUT name="textBox1" type="text" id="textbox1"> <INPUT type="button" onclick="javascript: var cal=window.open('Calender.aspx', '_blank', 'width=800, height=800' ); cal.focus();" value="Button" /> Dim js As String = "<script language='javascript'>window.opener.document.forms[0].textBox1.value= ' "+Calendar1.SelectedDate.ToString("MM/dd/yyyy")+" ';</script>" RegisterClientScriptBlock("setDate", js) Quote
uwking Posted February 11, 2004 Posted February 11, 2004 Request.QueryString does not return the name of the string id I have the same problem from this part. My problem is that Hidden1.value is not filled from Request.QueryString("textbox").ToString(); As a result, when i cliick on the date on the calendar, I get a javascript error... <INPUT name="textBox1" type="text" id="textbox1"> <INPUT type="button" runat="server" onclick="javascript:cal=window.open('Calender.aspx?textbox = textbox1','cal','width=800,height=800' );cal.setfocus()" value="Button" /> This ...window.open('Calendar.aspx?textbox=textbox1', ... "textbox" after the question mark is not recognized for some reason... I don't know why... I would really appreciate it if you can figure this out and let me know. Quote
WebJumper Posted February 11, 2004 Posted February 11, 2004 Re: Request.QueryString does not return the name of the string id I have the same problem from this part. My problem is that Hidden1.value is not filled from Request.QueryString("textbox").ToString(); As a result, when i cliick on the date on the calendar, I get a javascript error... What do you mean with "Hidden1.value" and "Request.QueryString("textbox)" ? Explain your problem and what at the moment don't work and i can help you! <INPUT name="textBox1" type="text" id="textbox1"> <INPUT type="button" runat="server" onclick="javascript:cal=window.open('Calender.aspx?textbox = textbox1','cal','width=800,height=800' );cal.setfocus()" value="Button" /> This ...window.open('Calendar.aspx?textbox=textbox1', ... "textbox" after the question mark is not recognized for some reason... I don't know why... I would really appreciate it if you can figure this out and let me know. What are you doing? You just open a window and the only url parameter (textbox) you are setting to "textbox1". what should happen?! nothing! Describe what you want to do and i will give you the solution... Regards, WebJumper! Quote
uwking Posted February 11, 2004 Posted February 11, 2004 OK, if you look at the original posting at the top (by utpal), he has code fragment as follows: -------------------------------------------------------------------------------- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Hidden1.Value = Request.QueryString("textbox").ToString() End Sub -------------------------------------------------------------------------------- Because on the webpage that has the textbox (where the picked date goes) with the id "textbox" gets passed as a parameter as follows: (Look where it's underlined) <INPUT type="button" runat="server" onclick="javascript:cal=window.open('Calender.aspx?textbox = textbox1','cal','width=800,height=800' );cal.setfocus()" value="Button" /> Then, in the following code ---------------------------------------------------------------------------------- Public Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Dim strScript As String = "<script>window.opener.document.forms(0)." + Hidden1.Value + ".value = '" strScript += Calendar1.SelectedDate.ToString("MM/dd/yyyy") strScript += "';self.close()" strScript += "</" + "script>" RegisterClientScriptBlock("anything", strScript) End Sub ---------------------------------------------------------------------------------- As you can see, "Hidden1.Value" is used here because it would hold the id parameter passed (i.e. "textbox"). So the variable "strScript" should be <script>window.opener.document.forms(0).textbox.value = '02/14/2004';self.close()</script> but in my case, this underlined "textbox" is not there, resulting in javascript error, meaning "Hidden1.Value" was never assigned with Request.QueryString method. If you still don't understand the problem, please let me know exactly what you don't understand. Thank you for your help. Quote
WebJumper Posted February 12, 2004 Posted February 12, 2004 OK, understood the problem! <script>window.opener.document.forms(0).textbox.value = '02/14/2004';self.close()</script> First of all, Hidden1.value is not requiered! Second, the forms(0) will not work, javascript needs forms[0] or take my exaple, will work too... C# string js = "<XXscript language='javascript'>window.opener.document.all['"+Request.QueryString["textbox"]+"'].value='"+Calendar1.SelectedDate.ToString()+"'; window.close();</XXscript>"; RegisterClientScriptBlock(Guid.NewGuid().ToString(), js) When converting to VB, note that the "[" xxxx "]" of javascript not be convertert to "(" xxxxx ")" !!!! The XXscript is written because of the forum, cut the XX away... Any more questions? Quote
uwking Posted February 12, 2004 Posted February 12, 2004 Thanks a bunch!!! Yo, thanks for your help. Those little things always end up annoying the hell outta me. One little question... You said "Hidden1.value" is NOT REQUIRED... but is it possible to use it at all... U don't have to answer that... only if you have time ^_^ Anyway, thanks again, dude Quote
WebJumper Posted February 13, 2004 Posted February 13, 2004 hidden1.value in the original post seems to be a textbox or something else. then, utpal wrote the Request.QueryString in this textbox's value attribute. in the next step he's writing the value from the hidden1.value into the register.clientscriptblock. that is not requiered because of the Request.QueryString get not lost and can be direct written... it's like this: string t = Request.QueryString["Something"]; Response.Write(t); and the same effet: Response.Write(Request.QueryString["Something"]); Now understood all right? Quote
uwking Posted February 13, 2004 Posted February 13, 2004 Thanks webjumper, but my question is WHY CAN'T YOU USE Hidden1.Value? In other words, why is it the case that Hidden1 (which is a HTML hidden field) could not hold the value of Request.QueryString ["Something"]? WHY DID IT NOT WORK? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.