Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set asp.net textbox value using javascript

I want to set the value of a asp.net textbox using javascript

My JS Code is:

document.getElementById('<%=txtFlag.ClientID %>').value = "Track";

My textbox is:

<asp:TextBox ID="txtFlag" runat="server" Visible="False"></asp:TextBox>

But it gives me an error document.getElementById(...)' is null or not an object

I dont understand what is wrong.

Please help.

like image 258
user2124167 Avatar asked Jan 10 '14 05:01

user2124167


1 Answers

<asp:TextBox ID="txtFlag" runat="server" Visible="False"></asp:TextBox>

Setting visible=false will cause this textbox to not appear in the rendered page. Remove this, and add display:none;

<asp:TextBox ID="txtFlag" runat="server" style="display:none;"></asp:TextBox>
like image 97
Abhitalks Avatar answered Sep 30 '22 03:09

Abhitalks