Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wanna to access value of box5(TextBox) in bottom code and modify its text in javascript attached file.
but i cant do it.i cant access value of box5.how i can??
thank ur help.
ASP.NET
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server" >
        <asp:TextBox id="box5" runat="server">
Posted
Updated 30-Aug-12 10:59am
v2
Comments
Dasaradhi_r 30-Aug-12 10:00am    
How did you attach the script file? If attached properly, there should not be any issues doing it.

You are accessing the server control in javascript.
So, you need to identify the textbox through ClientID as the id is changed after it renders in plain html.

document.getElementById("<%= box5.ClientID %>").value


Hope this helps.
cheers
 
Share this answer
 
Comments
r.kh 30-Aug-12 10:42am    
i wrote alert(document.getElementById("<%= box5.ClientID %>").value); but dosent show any alert
r.kh 30-Aug-12 10:45am    
and i wrote alert(document.getElementById("<%= box5.ClientID %>")); so alert is showed and its text was 'null'
Sandip.Nascar 30-Aug-12 11:02am    
Do one thing. After you run the page, view the source and see what you see the text id? Let us know.
Since the JavaScript is kept in a separate file, you'll have to pass the <%= box5.ClientId%> to the function when you are calling it. The attribute ID of a runat="Server" control can only be used from Code-Behind.

Regards,

— Manfred
 
Share this answer
 
Comments
r.kh 30-Aug-12 10:43am    
i wrote alert('<%=box5.ClientID %>'.value.toUpperCase()); but dosent show any alert
Manfred Rudolf Bihy 30-Aug-12 10:47am    
Depends on where exactly you wrote that. Please add some code to your question by using the improve question link below your question. If you added that line to your Javascript file it wouldn't work, because the JavaScript file is not processed on the server side.
Manfred Rudolf Bihy 30-Aug-12 10:51am    
Just try alert("<%= box5.ClientID %>") or alert('<%= box5.ClientID %>').

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