In web form: ResolveClientUrl
Code:
buttonImage: '<%=ResolveClientUrl("~/scripts/images/calendar.gif")%>',
In MVC: Url.Content
Code:
src="<%= Url.Content("~/Scripts/jquery-1.3.2.min.js")%>"></script>
Tuesday, August 31, 2010
How to solve problem: Page load fire twice when manually call __doPostBack in Javascript?
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>
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>
Subscribe to:
Posts (Atom)