Scenario:
When user press Enter key in a textbox, then do a postback by __doPostBack.
<script type="text/javascript">
$('#<%=TextBoxName.ClientID%>').keypress(function (event) {
if (event.keyCode == 13) {
__doPostBack('', '');
}
});
</script>
Problem: Page load fire twice.
Solution: put Textbox ClientID into first parameter of __doPostBack
<script type="text/javascript">
$('#<%=TextBoxName.ClientID%>').keypress(function (event) {
if (event.keyCode == 13) {
__doPostBack('<%=TextBoxName.ClientID%>', '');
}
});
</script>
No comments:
Post a Comment