Calender Popup

  • Thread starter Thread starter MasterChief
  • Start date Start date
M

MasterChief

I have a imagebutton that when you click on it, it will open up a page
containing a calender. When the pages starts up it gives the error
Object reference not set to an instance of an object.
and it highlights the line control.value =
Request.querystring("textbox").ToString()

Here is the my code


Public Class _popcal
Inherits System.Web.UI.Page
Protected WithEvents thedate As System.Web.UI.WebControls.Calendar
Protected WithEvents control As
System.Web.UI.HtmlControls.HtmlInputHidden

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
control.Value = Request.QueryString("textbox").ToString()
End Sub
Protected Sub Calendar1_SelectionChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
Dim script(4) As String
script(1) = "<script>window.opener.document.forms[0]." +
control.Value + ".value = '"
script(2) = thedate.SelectedDate.ToString("dd/MM/yyyy")
script(3) = "';self.close()"
script(4) = "</" + "script>"
RegisterClientScriptBlock("test", Join(script, ""))
End Sub
End Class
 
I have a imagebutton that when you click on it, it will open up a page
containing a calender.

How does it open the page?
When the pages starts up it gives the error
Object reference not set to an instance of an object.
and it highlights the line control.value =
Request.querystring("textbox").ToString()

Are you actually passing the querystring that you're expecting? E.g. if the
calendar page is called calendar.aspx, are you doing something like:

Response.Redirect("calendar.aspx?textbox=1") or whatever?
control.Value = Request.QueryString("textbox").ToString()

Put a breakpoint on the above line, run the app in debug mode and
interrogate the value of your querystring - I'm willing to bet you're not
actually including a querystring in your hyperlink to the calendar page...
 
The way I am calling it is below. As you can see after popcal.aspx
there is ?textbox=txtStartDate
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
RegisterStartupScript("openWindow", "<script
language='javascript'>window.open('popcal.aspx?textbox=txtStartDate','Calendar','toolbars=0,scrollbars=1,width=600,height=400,left
= 100,top = 100');</" & "script>")
End Sub
 
The way I am calling it is below. As you can see after popcal.aspx
there is ?textbox=txtStartDate
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
RegisterStartupScript("openWindow", "<script
language='javascript'>window.open('popcal.aspx?textbox=txtStartDate','Calendar','toolbars=0,scrollbars=1,width=600,height=400,left
= 100,top = 100');</" & "script>")
End Sub

Ah - now we're getting somewhere! What exactly is txtStartDate? Are you
trying to pass the name of a control or the value that control contains...?
 
It is the name of the textbox. What you do in the examples I have seen
is you have multple textboxes on a screen. What you do is when you open
a calender using a link you pass the name of the textbox. That way when
you click on a date in the calender it will know which textbox to
change on the main form.
 
It is the name of the textbox. What you do in the examples I have seen
is you have multple textboxes on a screen. What you do is when you open
a calender using a link you pass the name of the textbox. That way when
you click on a date in the calender it will know which textbox to
change on the main form.

I understand. So how are you referring to this textbox in your calendar
form? Presumably something like window.opener...?
 
Back
Top