How to pass the value using keypress event of asp textbox?
-
14-07-2021 - |
Question
Hi i am writing asp textbox controls. I want my pass the id using keypress event. Below code i am using but i m getting error.
The server tag is not well formed.
.aspx page
<asp:TextBox ID="tbxId" runat="server" Text='<%# Eval("ID") %>' Enabled="false">
<asp:TextBox ID="tbxValue" onkeyup="LoadAttributeValueLong("<%# Eval("ID") %>")" runat="server"
MaxLength="40" Text='<%# Eval("VALUE") %>'></asp:TextBox>
If anyone have any idea than please help me in this..
La solution
Binding expressions can't start from the middle of an attribute value. You need to write it like that:
<asp:TextBox onkeyup='<%# "LoadAttributeValueLong(" + Eval("ID") + ")" %>'
To pass also the value of the tbxId textbox:
<asp:TextBox onkeyup='<%# "LoadAttributeValueLong(" + Eval("ID") + ",\"" + tbxId.ClientID + "\")" %>'
And in your js function:
LoadAttributeValueLong(id, tbxId)
{
var tbxIdValue = $('#' + tbxId).val(); // jquery version
var tbxIdValue = document.getElementById(tbxId).value; // non jquery version
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow