将表单提交到非默认页面

发布于 2025-01-03 12:02:24 字数 361 浏览 1 评论 0原文

我在另一个例子中通过一些解决方法解决了这个问题,但这次我想弄清楚,因为我更好地理解了我的问题。

我的 asp.net 网页有一个搜索功能,可以根据 5 个字段搜索数据库。结果显示在网格视图中。网格视图是可编辑的,我可以更新值。问题是如果我想更新多个值,gridview 不允许这样做。所以我为复选框添加了一个额外的列。我添加了一个页脚,其中包含更新所有已检查记录的链接。

好吧,那么问题来了?如何将整个 gridview 发送到另一个可以捕获 gridview 值的页面?

默认情况下,页面会提交到其自身上。如果我更改默认操作页面、整个网格视图和搜索,则任何操作都不起作用。

那么如何将整个页面(或部分页面)提交到默认操作脚本之外的其他页面呢?

I solved this problem in another instance by making some workaround but I want to get it clear this time as I understand my problem better.

My asp.net net page has a search functionality that searches the database based on 5 fields. The result is displayed in the gridview. The gridview is editable and I can update values. The problem is if I want to update multiple values, gridview won't allow it. So I included an extra column for checkbox. I have added a footer which has link to update all checked records.

Ok so here is the problem? How do I send the whole gridview to another page where I can capture the gridview values?

By default the page is submitted onto itself. If I change the default action page, the whole gridview and search, nothing will work.

So how do I submit the whole page (or part of it) to a different page other than the default action script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风筝在阴天搁浅。 2025-01-10 12:02:24

我还没有专门用 gridview 尝试过这个,但我认为跨页回发应该可以工作。我的网站上也有搜索功能,这就是我使用的功能。

设置导致回发到目标页面的按钮的 PostBackUrl。
假设您的源页面是 search.aspx,目标页面是 SearchResult.aspx

在 search.aspx 中:

<asp:Button ID="btnSearch" runat="server" Text="Search"  CssClass="right" 
    ValidationGroup = "Search"
    PostBackUrl="~/SearchResult.aspx"
    onclick="btnSearch_Click"/>

表单将发布到 SearchResult.aspx。在 SearchResult.aspx 中,您添加此指令:

<%@ PreviousPageType VirtualPath="~/Search.aspx"  %>

在后面的代码中,您可以像这样访问任何控件:

PreviousPage.<mycontrol>

希望这会有所帮助。

I have not tried this specifically with a gridview, but I think a Cross Page PostBack should work. I have a search feature on my website as well and this is what I use.

Set the PostBackUrl of the Button that is causing the PostBack to the Destination page.
Let’s assume your source page is search.aspx and your destination page is SearchResult.aspx

Inside search.aspx:

<asp:Button ID="btnSearch" runat="server" Text="Search"  CssClass="right" 
    ValidationGroup = "Search"
    PostBackUrl="~/SearchResult.aspx"
    onclick="btnSearch_Click"/>

The form will be posted to SearchResult.aspx. Inside SearchResult.aspx, you add this directive:

<%@ PreviousPageType VirtualPath="~/Search.aspx"  %>

And in the code behind, you can acess any control like this:

PreviousPage.<mycontrol>

Hope this help.

苦笑流年记忆 2025-01-10 12:02:24

您是否尝试过使用Session?只需将 DataSourceGridview 本身添加到 Session 并将其加载到其他页面中,然后使用 Dispose()它。

祝你好运!

更新:

我过去通过Cross- 完成了此操作页面发布。这就是我现在出于测试目的所做的:

Default.aspx:

<asp:Button  ID="Button1" runat="server" Text="Button" onclick="Button1_Click" PostBackUrl="SearchResult.aspx" />

SearchResult.aspx.cs:

 protected void Page_Init(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            if (Page.PreviousPage.FindControl("GridView1") != null)
            {
                GridView grid = (GridView)Page.PreviousPage.FindControl("GridView1");
                grid.ID = "myGrid";
                this.form1.Controls.Add(grid);
            }
        }
    }

希望这会有所帮助。

Have you tried using the Session? Just add the DataSource, or the Gridview itself to the Session and load it in the other Page and then Dispose() it.

Good luck!

UPDATE:

I have accomplished this in the past through Cross-Page Posting. This is how I did it now for testing purposes:

Default.aspx:

<asp:Button  ID="Button1" runat="server" Text="Button" onclick="Button1_Click" PostBackUrl="SearchResult.aspx" />

SearchResult.aspx.cs:

 protected void Page_Init(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            if (Page.PreviousPage.FindControl("GridView1") != null)
            {
                GridView grid = (GridView)Page.PreviousPage.FindControl("GridView1");
                grid.ID = "myGrid";
                this.form1.Controls.Add(grid);
            }
        }
    }

Hopefully this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文