views:

549

answers:

2

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?

A: 

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

bdukes
yes - i've combed thru every line of code at least a dozen times. Frustrating.
Scott Ivey
A: 

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...

Scott Ivey