Thanks Ivar. I can see that using the ClientID property is a better way of getting the required *name* arg for the getElementById function. If only I had known... I would have not spent hours and hours in the debug immediate page drilling down to find the changed name of the control.
For anyone interested in the general problem of employing a javascript function in an ASP.NET 2 project which employs content pages inherited from a master page, I offer the following complete mini project as an illustration on how to do it. You may know of an even better way. (I have had several emails from folks who have had difficulty in that kind of situation.) However the code shown below works. And, employing Imar's suggestion above (using ClientID) would make it even better.
--------------------------
Here is a complete ASP.NET 2.0 project (
VB) employing a master page and a derived content page. The program demonstrates how one would go about using javascript (button click on the content page) to change the value of two labels: one inherited from the master page and one on the content page. Once one sees the technique employed, one can extend the principle in any number of ways for much clientside manipulation.
VV
-----------------------------------------
<%@ Master Language="
VB" CodeFile="MasterPage.master.
vb" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 24px; position: absolute;
top: 24px" Text="111111" Width="136px"></asp:Label>
<br />
<br />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
---------------------------------------
<%@ Page Language="
VB" MasterPageFile="~/MasterPage.master"
AutoEventWireup="false" CodeFile="Default.aspx.
vb" Inherits="_Default" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label2" runat="server" Style="left: 68px; position: absolute;
top: 128px" Text="222222" Width="76px"></asp:Label>
<input id="Button1" style="left: 36px; position: absolute; top: 160px" type="button"
value="html Button1" onclick="button1_onclick()" />
<script language="javascript" type="text/javascript" src="Default.
js"></script>
</asp:Content>
---------------------------------------
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Me.ClientScript.RegisterClientScriptInclude("xxx", "Default.
js")
End Sub
End Class
---------------------------------------
// JScript File
function button1_onclick() {
var x = document.getElementById("ctl00_ContentPlaceHolder1 _Label2");
x.innerText = "asdf";
var y = document.getElementById("ctl00_Label1");
y.innerText = "4567";
}
---------------------------------------