tags:

views:

117

answers:

2

I have a text box like this:

<asp:TextBox ID="txtLogin" runat="server" Text='<%# strUserID %>'></asp:TextBox>

strUserID is a string value set in my codebehind and I bind the textbox to see the value. I tried with <%= strUserID %>, but it doesnt work for me. can you please tell me why?

Also, I have a hidden field like this:

<input id="hdnUserID" runat="server" type="hidden" value='<%=txtLogin.ClientID %>'  />

and I have a function prints the hidden field value like this:

function CheckForValue()
{
    var uid = window.document.getElementById('<%= txtLogin.ClientID %>').value;
    alert(hdnUserID);

    return false;
}

But this alert always prints as "[object]". Can anyone please explain this? Looks like <%= value %> doesnt work at all. But I have seen in my earlier projects where the existing code has these kinda lines!!

+1  A: 

Try taking the innerHTML or innerText values of the textbox for your message.

Neil Barnwell
+2  A: 

If your strUserID value is a member variable set in the code behind make sure it's access modifier is declared as at least protected or you will not be able to access it. Also the notation you want to use is <%= strUserID %> not <%# strUserID %> # is used to get the value of a databound dataItem.

Also in your second point I dont see the need for your hidden field. Can you not just use the following to get your textbox value?

function CheckForValue()
{
    var textValue = window.document.getElementById('<%= txtLogin.ClientID %>').value;
    alert(textValue);

}
Sheff
If the "strUserID" variable were not atleast Protected in scope, I doubt if the code would even compile.
Cerebrus
When using server tags in the code pages they are evaluated at runtime so it would indded compile
Sheff