Postback problem for my custom control load wizard

2019-08-26 23:05发布

I have some problem that happens when controls are loaded in init and it still doesn't help me to get proper postback event fired on time.

I am trying to create a rich wizard control that will enable switching, links with description, completely customized steps, integration of substeps - by using dynamic control load that is avoids standard asp.net wizard way of loading.

Idea is to have on left part navigation, on right part content, or substeps that are run from right part and that go over whole area.

Download source project

2条回答
何必那么认真
2楼-- · 2019-08-26 23:51

Ok, I re-read the question, and here is what you have to do. You have to re-load these controls on each postback, give them always the same "Id". This can be done in Page_Init or in Page_Load event. And of course, you have to re-attach event handlers on each post back.

查看更多
叼着烟拽天下
3楼-- · 2019-08-26 23:56

Many thanks.. well i found the answer - id was the problem, in load control method. I was doing this wizard.. well most of things work now. If someone is interested to see how does this works.. there are some updates:

public void LoadSplitViewControl(string path)
{
    SwitchNavigationView(NavigationView.SplitView);
    LastNavigationView = NavigationView.SplitView;
    LoadControl(SplitControlLoader, path, "LoadedControlSplit");
}

public void LoadSingleViewControl(string path)
{
    SwitchNavigationView(NavigationView.SingleView);
    LastNavigationView = NavigationView.SingleView;
    LoadControl(SingleControlLoader, path, "LoadedControlSingle");
}

public void LoadSingleViewControlAsClear(string path)
{
    SwitchNavigationView(NavigationView.SingleView);
    LastNavigationView = NavigationView.SingleView;
    LoadControlAsClear(SingleControlLoader, path, "LoadedControlSingle");
}

private void LoadControl(PlaceHolder holder, string path, string ID)
{
    UserControl ctrl = (UserControl)Page.LoadControl(path);
    ctrl.ID = ID;
    LastControlPath = path;
    holder.Controls.Clear();
    holder.Controls.Add(ctrl);
}

//as i am using steps loaded controls using splitview and substeps controls using single view sometimes viewstate will not be valid so error will be thrown but u can resolve this by using LoadSingleViewControlAsClear that will load below method.

private void LoadControlAsClear(PlaceHolder holder, string path, string ID)
{
    UserControl ctrl = (UserControl)Page.LoadControl(path);
    ctrl.ID = ID;
    LastControlPath = path;
    ctrl.EnableViewState = false;
    holder.Controls.Add(ctrl);
}

/another cool idea i am using for such an wizard is that i am not using viewstate but rather session object for saving values collected over steps. My session object key is generated by authenticated username and pageguid - so u can have many loaded pages and each of them will handle different session object./

public Guid PageGuid
{
    get
    {
        if (PageGuidField.Value == "")
        {
            var _pageGuid = Guid.NewGuid();
            PageGuidField.Value = _pageGuid.ToString();
            return _pageGuid;
        }
        return new Guid(PageGuidField.Value);
    }
}
查看更多
登录 后发表回答