• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 735
  • Last Modified:

Javascript pop up not working, added to master page

Hi all,
I had a calendar control working perfectly in a .aspx page. I wired the .aspx to Masterpage.Now the calendar control fails to recognise the form and the element( a textbox), it dumps the date into.
It gives me an : ct100_Maincontent_mytextbox is null or the object is not re..." error.
I have attched the code snippet below.
PLEASE HELP.
'This is how i call The popup calendar
<a href="javascript:calendar_window=window.open('Controls/Calendar.aspx?textbox=<% =txtMFgDate.ClientID %>','calendar_window','width=235,height=218 top=200 left=500','scrollbars=no,status=no,minimize=no,resizable=no');calendar_window.focus()"><img alt="PopUp Calendar" src="Images/popup-calendar.gif" /></a>
 
'this is the code behind in calendar control
   Protected Sub Change_Date(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim strjscript As String = "<script type=""text/javascript"">"
        strjscript &= "window.opener." & _
              HttpContext.Current.Request.QueryString("textbox") & ".value = '" & _
              myCalendar.SelectedDate & "';window.close();"
        strjscript = strjscript & "</script" & ">" 'Don't Ask, Tool Bug
 
        Literal1.Text = strjscript  'Set the literal control's text to the JScript code
 
    End Sub

Open in new window

0
SaraDob
Asked:
SaraDob
  • 5
  • 2
1 Solution
 
silemoneCommented:
the id's change on controls when inside of a masterpage...it add cl00...when you run code, look in the view source and retrieve ID from there...
0
 
SaraDobAuthor Commented:
Thanks for the quick response silemone.
I view in the source .i got "ctl00$MainContent$txtMFgDate" as my textbox name, when in masterpage content.
So should i change textbox id="ctl00$MainContent$txtMFgDate" that now instead of textbox="My original textbox name" ?
If so, then i have go change of all the textbox names throught out my site, that has calendar pops or any other kind od javapops's ?
0
 
SaraDobAuthor Commented:
I replaced  "ctl00$MainContent$txtMFgDate as my textbox name and run it..but still i get the same issue..
Please reply
 
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
silemoneCommented:
ok..I was looking at the wrong javascript....

you are using <%= control.ClientID %> so you shouldn't have to change id = ...

whenever you need to access that control, you would just use control.ClientID the way you did...

hmmm.....
0
 
SaraDobAuthor Commented:
I'm using this script, to put back the Selected date. This code is in Code behind of the calendar.Can you please look, and tell whats wrong here>
Thanks..Hope it will be solved soon

Protected Sub Change_Date(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Dim strjscript As String = "<script type=""text/javascript"">" 
strjscript &= "window.opener." & _ 
HttpContext.Current.Request.QueryString("textbox") & ".value = '" & _ 
myCalendar.SelectedDate & "';window.close();" 
strjscript = strjscript & "</script" & ">" 'Don't Ask, Tool Bug 
Literal1.Text = strjscript 'Set the literal control's text to the JScript code 
End Sub 

Open in new window

0
 
SaraDobAuthor Commented:
Well, Itried it on my own.I cant possible hard code the Control iDs, as There will be other pop up request from other pages.
So this is what i used to send the textbox name to the calendar control, through the javascript function : <%=textbox1.ClientID%>
0
 
SaraDobAuthor Commented:
Finally i used In code behind of calendar control to put back the date, into the calling textbox:

Protected Sub Change_Date(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim strjscript As String = "<script language='javascript'>"
strjscript += "window.opener.document.forms[0].elements['"
strjscript += (HttpContext.Current.Request.QueryString("textbox") & "'].value= '") & myCalendar.SelectedDate & "';"
strjscript += "window.opener.document.forms[0].elements['"
strjscript += (HttpContext.Current.Request.QueryString("textbox") & "'].focus();")
strjscript += "window.close()"
strjscript += "</" & "script>"
LiteralCalendar.Text = strjscript
End Sub
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now