Click here to Skip to main content
15,910,980 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new in ASP and developing an web application that requires user to register to the system. In registration.aspx, I have ASP controls.

My problem is to access the ASP controls using JavaScript. Suppose for validating a text input i need to write something like this:

JavaScript
document.getElementbyId("myControl").value="Something";


But for ASP controls I don't get such attributes (like value, selectedindex etc.). If I put these codes into C# that requires post back pages while executing code. So, as a use I never expect pages to post back every while I make changes to any of the controls in pages.

I tried to use ClientID property as suggested by MSDN. But ClientID property is only available at ASP.NET 4 but not in ASP.NET 3.5.

I am using ASP.NET 3.5. How can I do these things. Can you please help me out? Thanks in advance.
Posted

You can use ClientID property. One thing you can do is check your rendered page's source and see the control's ID generated by ASP.NET and the one appearing in your javascript function are the same.

C#
document.getElementById('<%= myControl.ClientID %>').value="something";
 
Share this answer
 
Have you give "runat=server" property to your controls ? if not then give it.
try out simple script

XML
<script language="JavaScript">
   function CallMe()
     {
          alert("Yes..first POP up from javascript");
          return false;
     }
 </script>
 </head>
 <body> Welcome to javascript example!
        <input type="submit" id="sub1" runat="server" onclick="return CallMe();">
 </body>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900