No keypress event for asp textbox
Hello i need to work on keypress event of asp textbox but keypress eve开发者_开发技巧nt not available for the asp textbox. Is there alternative available for this problem? Plz help!
Make use of keypress event of javascript + textbox
and call the serverside function by using ajax or using pagemthods.
.cs file
[ScriptMethod, WebMethod]
public static string docall()
{
return "Hello";
}
.aspx file
<script type="text/javascript">
function btnAccept_onclic() {
PageMethods.docall(onSuccess, onFailure);
}
function onSuccess(result) {
alert(result);
}
function onFailure(error) {
alert(error);
}
</script>
check this : http://blogs.microsoft.co.il/blogs/gilf/archive/2008/10/04/asp-net-ajax-pagemethods.aspx
TextBox1.Attributes.Add("onkeypress", "return clickButton(event,'" + Button1.ClientID + "')");
The code-behind generates the following:
<input name="TextBox1" type="text" id="TextBox1" onkeypress="return clickButton(event,'Button1')" />
This causes the web control Button1
to be clicked when the enter key is hit inside TextBox1
.
Try this :
Just make TextBox's
AutoPostBack
True
(To do this, click TextBox then press F4. Then in properties, make AutoPostBack True)And then use TextBox
OnTextChanged
event.
(To do this, select Design View. Then click the TextBox again. Then click events tab (the Events button is in the upper side) and double click TextChanged event)
This is help for you for onkey press and allow numeric values
function fncInputNumericValuesOnly() { if (!(event.keyCode == 45 || event.keyCode == 46 || event.keyCode == 48 || event.keyCode == 49 || event.keyCode == 50 || event.keyCode == 51 || event.keyCode == 52 || event.keyCode == 53 || event.keyCode == 54 || event.keyCode == 55 || event.keyCode == 56 || event.keyCode == 57 || event.keyCode == 8 || event.keyCode == 190 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 16)) { event.returnValue = false; } } <asp:TextBox ID="txtRphone" runat="server" CssClass="NormalTextBox" onkeypress="fncInputNumericValuesOnly()"
MaxLength="15"></asp:TextBox>
精彩评论