admin管理员组文章数量:1418592
We're currently performing a cross-page postback using the PostBackUrl
of an asp:Button
:
<asp:Button runat="server" PostBackUrl="processing.aspx" />
which generates this javascript onclick
stuff:
<input type="submit" name="ctl03"
onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl03', ', false, ', 'processing.aspx', false, false))" />
We would like to switch it to use a plain ol' <button runat="server">
(easier to style) however PostBackUrl
is not supported on them.
So I thought: what if simply use said JavaScript in my <button>
element?
<button runat="server" name="ctl03"
onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl03', '', false, '', 'processing.aspx', false, true))">
</button>
And waddayaknow, it works.
Has anyone ever seen this done before? What harm will e to me or my children if I proceed with this?
We're currently performing a cross-page postback using the PostBackUrl
of an asp:Button
:
<asp:Button runat="server" PostBackUrl="processing.aspx" />
which generates this javascript onclick
stuff:
<input type="submit" name="ctl03"
onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl03', ', false, ', 'processing.aspx', false, false))" />
We would like to switch it to use a plain ol' <button runat="server">
(easier to style) however PostBackUrl
is not supported on them.
So I thought: what if simply use said JavaScript in my <button>
element?
<button runat="server" name="ctl03"
onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl03', '', false, '', 'processing.aspx', false, true))">
</button>
And waddayaknow, it works.
Has anyone ever seen this done before? What harm will e to me or my children if I proceed with this?
Share Improve this question asked Aug 18, 2009 at 2:54 Crescent FreshCrescent Fresh 117k27 gold badges157 silver badges140 bronze badges 2- Just for clarification - why are you putting the cross-page postback on the control rather than the form? Do you have some controls that post back to the original page? – Mark Brittingham Commented Aug 18, 2009 at 3:17
- @Mark: yes, some buttons postback to the same page, one should not. – Crescent Fresh Commented Aug 18, 2009 at 12:03
2 Answers
Reset to default 5Interesting question, I just looked ClientScript's GetPostBackEventReference method and here what I get :
Button at ASP.NET page :
<button id="Button2" runat="server" name="Button2"></button>
At code-behind :
PostBackOptions postBackOptions = new PostBackOptions(Button2);
postBackOptions.ActionUrl = "processing.aspx";
Button2.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(postBackOptions));
Rendered result :
<button id="Button2" name="Button2"
onclick="WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("Button2", "", false, "", "processing.aspx", false, true))">
</button>
"Probably not", but you're relying on implementation-details of the ASP.NET JavaScript that may change over time.
I'll be honest, I didn't actually realise there was a '<button>' HTML element.
本文标签: aspnetPostBackUrl not available on Html ButtonsStack Overflow
版权声明:本文标题:asp.net - PostBackUrl not available on Html Buttons - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745297716a2652178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论