Calendar pop-up won't return value in Firefox

M

msch-prv

I created a pop-up window using the ASP.NET 2.0 calendar in a distinct
file (calpopup.aspx). The calendar pops up when clicking on a
linkbutton and copies the selected day back into the textbox. This
works fine in IE.

In Firefox however, while the calendar is displayed correctly, the date
is not copied back. The console javascript reports the error:
'window.opener.document.forms is not a function'.

How can I trick FF into executing the script? Thanks for any advice,
Mark

Event that fires after a day is clicked (calpopup.aspx):

Protected Sub Change_Date(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim cs As ClientScriptManager = Page.ClientScript
Dim cstype As Type = Me.GetType()
Dim cskey As String = "Test-CalPopup"

Dim strScript As String =
"<script>window.opener.document.forms(0)." + control.Value + ".value =
'"
strScript += calDate.SelectedDate.ToString("dd/MM/yy")
strScript += "';self.close()"
strScript += "</" + "script>"

If Not
ClientScript.IsClientScriptBlockRegistered("Test-CalPopup") Then
cs.RegisterClientScriptBlock(cstype, cskey, strScript)
End If
End Sub
 
F

Flinky Wisty Pomm

Er... FF is right, forms is not a function and forms(0) is therefore an
invalid function call.

Tried forms[0] ?
 
M

MatsL

I always use getElementById() when I set values of controls with javascript.

Try:
"window.opener.document.getElementById('" + control.Value + "').value;"

instead of
window.opener.document.forms(0)." + control.Value + ".value

//Mats
 
M

msch-prv

Thanks for the reply, Flinky. Changing (0) to [0] does the trick!

When I use this function in a multi-page master/details environment, I
am getting IE script errors. For instance, if I want to copy the
calendar value in, say, textbox 'Prjs_BegDay' of script 'Prjs.aspx',
the following error pops up:

'window.opener.document.forms.0.Prjs_BegDay is null or is not an
object'

I suppose the runtime/browser does not know how/where to locate the
textbox. How would I modify the function to solve this?

TIA, Mark
 
M

msch-prv

The referencing problem is related to the master/details model.

After looking at the browser source and some searching, I found out
that in a master/detail configuration, control IDs do change to sthg
like:

<ID of Master Page Control>$<ID of Content Place Holder>$Text1 control>

For example in a details form, the textbox ID="Prjs_BegDay" typically
changes to:
name="ctl00$CONTENT$Prjs_BegDay" id="ctl00_CONTENT_Prjs_BegDay"

So, to properly reference controls, I came up with the following
heuristic solution. However, I don't know if this approach is correct.

Step 1. I added an init event to consistently rename the master ID as
'Master'.

Step 2. I substitued all IDs of the controls invoked by javascript
functions by their extended IDs noting the placeholders where they are
located in. For example, if control 'id="Prjs_StartDay"' is located in
contentplaceholder 'CONTENT', it will be invoked in a js function as
'id="Master_CONTENT_Prjs_BegDay"'.

The following now works:

<asp:TextBox ID="Prjs_BegDay" runat="server"...>
<a href="javascript:;"
onclick="window.open('calpopup.aspx?id=Master_CONTENT_Prjs_BegDay',...>

Please advise if this is correct. TIA, Mark
 
Joined
Sep 19, 2006
Messages
1
Reaction score
0
Thanks Flinky/Mark, I ran into this exact same issue with a calendar pop-up as well. The only thing that I did differently was use the UniqueID property of the textbox control instead of ID. This alleviated the need to build the ID via heuristics.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,707
Messages
2,569,344
Members
44,635
Latest member
Matt231

Latest Threads

Top