Reach components in content using javascript

M

Magnus

Hello,

I am very new to javascript, but would like to do some client operations with some server controls.
I have a masterpage with a contentplaceholder. I think what I'm trying to accomplish is quite obvious (I hope).

Here's the master page:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" 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>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server"></asp:contentplaceholder></div> </form></body></html>

And the content page:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<script type="text/javascript">
function recal() {
var txt = Number(document.getElementById("TextBox1").value);
var lbl = Number(document.getElementById("Label1").value);
document.getElementById("Label1").value = txt+lbl; }
</script>
<asp:TextBox ID="TextBox1" runat="server" onchange="recal()"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="0"></asp:Label>
</asp:Content>

I know that a simple answer to get this to work is to use html object, but above is of cause just an example (calculator addition) of a larger server solution.

Please help
/Magnus
 
B

bruce barker

asp.net munges the name of controls to make them unique. you use the
server controls ClientID.

var txt = Number(
document.getElementById("<%=TextBox1.ClientID%>").value);

note: a label render as a span and will not have value property. it does
have an innerHTML property (at least in several browsers)

-- bruce (slwork.com)
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top