There is (suppose to be) a label or textbox in hidden mode that from the code behind will be set (text value) to “user” or “manager”.
I want to be able to make a JavaScript verify what is the value of the (hidden) textbox/label when there’s a click event on given table row (<tr>) which dose not have runat="server" property set.
If a client tries to click on that row (actually that row has a few textbox elements)
so if client try to edit e.g. click on the row
then action taken by a js function like alert("no edit allowed") will be taken.
<tr id="TR_editTimein" onClick="javascript:CheckIfManager();">
<td> <input type="text" id="timeIn" /></td>
</tr>
-
If code behind recognize a manager(from
Request.QueryString) it sets the hidden LBL or TXTBX with value “manager” -
JavaScript
onClickevent overTR_editTimeinwill triggerCheckIfManager()
function -
CheckIfManager()will ask for the value of the hidden element and if value is “user” it will do alert(“no edit option for non Managers”)
For now, what happens is if i set that say aspTextBox to Visible=false
JavaScript also don’t see it.
what is the right way to validate if the client is user or manager?
If you set
Visible=False, the ASP.NET control wont even get rendered in browser ( client -side ). That means DOM won’t have that object and so you cannot fetch that object usinggetElementById.The alternative is to use an
asp:HiddenFieldwhich renders asinput type='hidden'.If you have a resolute and unyielding need to use
asp:Labelorasp:TextBoxset thedisplay:none;from code-behind like thisThat way the object will be rendered in browser and hidden from user allowing you to fetch that using JavaScript.