跨页发布Asp.net [英] Cross Page Posting Asp.net

查看:79
本文介绍了跨页发布Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一页到另一页进行交叉张贴,但是我有
主页上的两个按钮,我希望收到帖子的页面
确定单击了哪个按钮:

I would like to do a cross post from one page to another, but I have
two buttons on the main page, and I want the page receiving the post to
determine which button has been clicked:

<body>
<form id="form1" runat="server">
<div>
<asp:Button PostBackUrl="HandlerPage.aspx" ID="Button1"

runat="server" Text="Do This" /><br />
<asp:Button PostBackUrl="HandlerPage.aspx" ID="Button2"

runat="server" Text="Do Something Else" />&nbsp;</div>
</form>
</body>



HandlerPage.aspx可以测试Page.PreviousPage来查看它是否正在
由交叉点调用,但是如何确定Button1或Button2
被点击了吗?

我现在所能想到的都是令人不快的选择:
1)整理会话对象
2)使用查询字符串
3)查看Request.form并检查Button1的ClientID,如下所示:



HandlerPage.aspx can test Page.PreviousPage to see if it is being
called by a cross post, but how do I determine if Button1 or Button2
was clicked?

All I can think of right now are unpalatable options:
1) Clutter up the session object
2) Use a Querystring
3) Look at Request.form and check the ClientID of Button1 as below:

Button Button1 = (Button)PreviousPage.FindControl("Button1");
Button Button2 = (Button)PreviousPage.FindControl("Button2");
if (Request.Form[Button1.ClientID]==Button1.Text){
Response.Write ("Button1 CLicked");
}
else if (Request.Form[Button2.ClientID] == Button2.Text)
{
Response.Write("Button 2 Clicked");
}
}


后一种策略似乎可行,但我不禁会认为
必须有一种更清洁的方法.


This latter strategy seems to work, but I can''t help thinking that
there must be a cleaner way.

推荐答案

一种明显的方法是将按钮的ID放在URL上.跨页面发布是一个真正的技巧,最好不要这样做.您可以将两个页面"放在一个页面中作为控件.甚至更好的是使用MVC,它比Webforms更好.
The obvious way to do this, is to put the id of the button on the URL. Cross page posting is a real hack, you''d be better off not doing it. You can put both ''pages'' inside the one page as a control. Even better would be to use MVC, which is way better than webforms.



请参阅以下链接:
ASP.NET 2.0中的跨页发布 [ ^ ]
http://msdn.microsoft.com/en-us/library/ms178139.aspx [ ^ ]
http://stackoverflow.com/questions/1099020/asp-net-cross-page-posting [^ ]

此处 [
Hi,
Refer these links:
Cross Page Posting in ASP.NET 2.0[^]
http://msdn.microsoft.com/en-us/library/ms178139.aspx[^]
http://stackoverflow.com/questions/1099020/asp-net-cross-page-posting[^]

Here[^] is an example for cross page posting.
--Amit


这篇关于跨页发布Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆