Javascript and Masterpages

G

Guest

I am using a popup Calendar to populate a textbox. When the textbox is on a
form without content control, it works fine. the script
is:<script>window.opener.document.forms(0).txtDate.value
='3/20/2006';self.close()</script>

However, when the textbox is within a content control, it does not work. I
changed the script to <script>window.opener.document.Content(0).txtDate.value
='3/13/2006';self.close()</script> still not working.
 
K

Ken Cox - Microsoft MVP

Hi Mori,

Once you start using master pages and containers, the names of the controls
change dramatically. You need to use the name that ASP.NET gives the
control. You can get that by using the control's ClientID property.

At also means you need to create the JavaScript dynamically.

Here's the idea:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled
Page" %>

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, ByVal e As System.EventArgs)
Page.ClientScript.RegisterStartupScript _
(Me.GetType, "cal", "document.forms[0]." & _
txtDate.ClientID & ".value='3/20/2006';", True)
End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:textbox id="txtDate" runat="server"></asp:textbox>
</asp:Content>


Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top