当
我在 ASCX 页面中有一个表单操作设置为外部 URL
里面有一个标准的 ASP 链接按钮
当我在表单标记上设置 action="http://external.url"
时,事件“bSignin_Click”永远不会被触发。但是,当我删除该操作时,它会按预期工作。我认为对于 runat='server'
表单,表单总是会回发?我需要从操作属性中读取 URL,然后使用页面中的一些隐藏输入值重定向到该 URL。
谢谢。
I have a form action in an ASCX page set to an external URL
<form id="fLoginForm" runat="server" action="http://external.url" method="post" defaultbutton="bSignIn">
Inside there is a standard ASP linkbutton
<asp:LinkButton CssClass="btn" ID="bSignIn" runat="server" Text="Sign In" OnClick="bSignIn_Click" />
The event "bSignin_Click" never gets fired when I have action="http://external.url"
set on the form tag. However when I remove the action, it works as expected. I thought for runat='server'
forms, the form would always post back? I need to read the URL from the action attrib and then redirect to it with some hidden input values also in the page.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实际上,当您单击链接按钮时,您的表单将回发以处理单击事件。在表单操作中,您指定了操作 URL,它将被重定向到您的操作 URL。
从逻辑上讲你做错了,你必须删除操作 URL
Actually when you click on the link button, your form will postback to handle the click event. On form action you have given action url and it will be redirected to your action URL.
Logically you are doing wrong, you have to remove action URL
为什么不在处理程序
bSignIn_Click()
中处理登录功能?然后使用 Response.Redirect("http://external.url"); 将用户重定向到所需的 URL;
Why not handle the sign-in functionality within the handler
bSignIn_Click()
?And then redirect the user to the desired URL using
Response.Redirect("http://external.url");
这个行为实际上非常奇怪,因为它在同事机器上的行为完全不同 - 重新检查 SVN 的解决方案,并且它有效。奇怪的。
Well the behaviour was actually very weird, as it behaved completely differently on a colleagues machine - rechecking in the solution from SVN, and it worked. Strange.
对于您拥有的表单,当单击“链接”按钮时,表单中的所有数据都会发布到 URL,而不是发布回同一表单(因此称为“回发”),您可以在其中处理所有这些事件。
您可以尝试将该 URL 写入隐藏字段(而不是表单操作属性),并在代码隐藏中读取该隐藏字段值。
With the form you have, when the Linkbutton is clicked, all the data in your form is posted to the URL, and not posted back to the same form (hence the term "postback") where you can handle all those events.
You can try writing that URL in a hidden field (instead of form action attribute) and read that hidden field value in codebehind.