views:

122

answers:

2

work on asp.net vs 05 C#.Master page header contain the bellow code

<script type="text/javascript" language="javascript" src="JScript.js"></script>

from my one page i call the javascript method

 <asp:TextBox ID="txtLength" runat="server" >0</asp:TextBox>

 <asp:TextBox ID="txtHeight" runat="server" onchange="javascript:DoChange();">0</asp:TextBox>

javascript method is below :

 {
      alert("hello world");**//get this alert but don't get the bellow alert.**
     var a=document.getElementById("txtLength");
     var b=document.getElementById("txtHeight");
      alert(a.value*b.value);
   }

want to show value on message box .Actually want to calculate the Sft,How to ?

+2  A: 

The DOM ID of the text boxes is not the same as the server side asp.net ID. In order to get the client DOM ID, use the ClientID property:

 var a=document.getElementById("<%= txtLength.ClientID %>");
 var b=document.getElementById("<%= txtHeight.ClientID %>");

Also, you are attempting to multiply two strings together even if that works.

More generally, I recommend using a javascript debugger like Firebug or Chrome's debugger. Then you will be able to see precisely what line the errors are occurring on and what they are.

recursive
Of course, it cannot be done on a `.js` file - it isn't server-side. And even then, it has no access to the page and its controls
Kobi
thnaks .now i can do it from single page ,but i can not use javascript from masterpage
HelloBD
A: 

Kindly refer to the below link

http://social.msdn.microsoft.com/Forums/en/netfxjscript/thread/dc7c1aa6-7571-460c-b039-13cdba8c396c

solairaja
I have not found ClientScriptManager to be helpful. It's possible to do almost everything you need by directly embedding javascript in the markup and specifying OnClientClick and its ilk. Perhaps I'm missing something, but ClientScriptManager does not seem to do much you can't do this way. And I find it to be wildly confusing.
recursive