DotNetNuke ObjectDataSource.SelectMethod 未保存在视图状态中

发布于 2024-07-15 19:37:27 字数 877 浏览 5 评论 0原文

我正在使用 DotNetNuke 4.9.2 并且遇到了一个奇怪的问题。

我正在开发的模块中有一个 MultiView,并且其中一个视图有一个绑定到 ObjectDataSource 的 GridView。

在单独的视图中,我有几个按钮可以在第二个视图中切换 ObjectDataSource 的 SelectMethod,然后将该视图设置为活动状态。 一切正常,直到网格在第二个视图上排序 - 这会导致回发并且 ODS 以某种方式拾取其原始 SelectMethod。 不过,在代码隐藏中同时分配的 SelectParameters 仍然存在。

在我看来,ObjectDataSource 应该记住视图状态中的 SelectMethod,不是吗?

<asp:ObjectDataSource runat="server" ID="MyObjectDataSource" SelectMethod="MyFirstSelectMethod" TypeName="Whatever"></asp:ObjectDataSource>

protected void Button1_Click(object sender, EventArgs e)
{
    MyObjectDataSource.SelectMethod = "MyNewMethod";
    // more code here to change the parameters as well...
    MyMultiView.SetActiveView(MyView2);
}

当我单击该按钮时,网格将按预期显示。 当我单击 GridView 的列标题之一并中断页面加载以检查 SelectMethod 时,它已恢复为标记中声明的标题。

关于我的问题可能在这里有什么建议吗?

I'm using DotNetNuke 4.9.2 and am running into an odd issue.

I have a MultiView in the module that I'm developing, and in one of the views have a GridView that is bound to an ObjectDataSource.

In a separate view, i have several buttons that will switch the SelectMethod of the ObjectDataSource in the 2nd view and then set that view active. That all works fine, until the grid is sorted on the 2nd view - which causes a postback and the ODS somehow picks up its original SelectMethod. The SelectParameters that are assigned at the same time in the code-behind stick though.

Seems to me that the ObjectDataSource should be remembering the SelectMethod in viewstate, shouldn't it?

<asp:ObjectDataSource runat="server" ID="MyObjectDataSource" SelectMethod="MyFirstSelectMethod" TypeName="Whatever"></asp:ObjectDataSource>

protected void Button1_Click(object sender, EventArgs e)
{
    MyObjectDataSource.SelectMethod = "MyNewMethod";
    // more code here to change the parameters as well...
    MyMultiView.SetActiveView(MyView2);
}

When I run that button click, the grid displays as expected. When I click on one of the column headers for the GridView and break in the page load to inspect the SelectMethod, it has reverted to the one declared in the markup.

Any suggestions as to what my problem could be here?

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

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

发布评论

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

评论(2

初懵 2024-07-22 19:37:27

我猜您已经确保页面重新加载时没有重置 .SelectMethod ?

I'm guessing you've made sure that you're not resetting .SelectMethod when the page reloads?

夏了南城 2024-07-22 19:37:27

我最终通过仅使用页面属性来保存 selectmethod 来解决这个问题,然后在每次回发时重置它......

protected string MySelectMethod
{
    get
    {
        return (string)ViewState["MySelectMethod"] ?? MySearchResultsDataSource.SelectMethod;
    }
    set
    {
        ViewState["MySelectMethod"] = value;

        MySearchResultsDataSource.SelectMethod = value;

    }
}

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        MySearchResultsDataSource.SelectMethod = MySelectMethod;
    }
}

protected void MyButton_Click(object sender, EventArgs e)
{
    MySelectMethod = "MyNewMethod";
}

仍然不确定为什么 SelectMethod 属性不坚持在 nuke 中的回发上。 我确信这在过去的 ASP.NET 项目中对我来说效果很好......

I ended up working around the issue by just using a page property to hold the selectmethod, and then resetting it on each postback...

protected string MySelectMethod
{
    get
    {
        return (string)ViewState["MySelectMethod"] ?? MySearchResultsDataSource.SelectMethod;
    }
    set
    {
        ViewState["MySelectMethod"] = value;

        MySearchResultsDataSource.SelectMethod = value;

    }
}

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        MySearchResultsDataSource.SelectMethod = MySelectMethod;
    }
}

protected void MyButton_Click(object sender, EventArgs e)
{
    MySelectMethod = "MyNewMethod";
}

Still not sure why that SelectMethod prop doesn't stick on a postback in nuke. I'm sure this has worked fine for me in straight asp.net projects in the past...

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