admin管理员组文章数量:1323723
I do not have access to the <body>
tag because it is in masterpage.
I want to trigger an automatic postback when the page load as:
<script type="text/javascript">
window.onscroll= __doPostBack("<%= button.ClientID %>", "");
</script>
where should I put this code? I get a Not implemented JS error if I place it just before the </asp:Content>
tag.
Any idea how I should do this ?
PS: I need to trigger that postback because I want to populate an updatepanel when the page loads
I do not have access to the <body>
tag because it is in masterpage.
I want to trigger an automatic postback when the page load as:
<script type="text/javascript">
window.onscroll= __doPostBack("<%= button.ClientID %>", "");
</script>
where should I put this code? I get a Not implemented JS error if I place it just before the </asp:Content>
tag.
Any idea how I should do this ?
PS: I need to trigger that postback because I want to populate an updatepanel when the page loads
Share Improve this question edited Feb 16, 2011 at 11:08 Shadow Wizzard 66.4k26 gold badges146 silver badges209 bronze badges asked Feb 15, 2011 at 21:07 RyanRyan 5,50625 gold badges77 silver badges129 bronze badges1 Answer
Reset to default 4You can have such code and place it anywhere:
<% if (!Page.IsPostBack) { %>
<script type="text/javascript">
window.onload = function() {
__doPostBack("<%= button.ClientID %>", "");
}
</script>
<% } %>
Assuming you're using C# - if you have VB.NET the syntax will be bit different.
Edit: to avoid using <%
and %>
you can have this in the Page_Load of your page:
if (!Page.IsPostBack) {
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "auto_postback", "window.onload = function() { __doPostBack(\"" + button.ClientID + "\", \"\"); }; ", true);
}
Edit II: alternative way with better chance of working is to have such JS code instead:
"window.onload = function() { var buttonID = '" + button.ClientID + "'; alert('ID: ' + buttonID + ', clicking...'); document.getElementById(buttonID).click(); }; "
This will hopefully show you the client ID of the button then auto click it. If no luck make sure the ID is correct and really exist in the document and we'll try to find what is the problem.
本文标签: aspnettrigger automatic postback in javascriptStack Overflow
版权声明:本文标题:asp.net - trigger automatic postback in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742123423a2421828.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论