Postback problem for my custom control load wizard

匆匆过客 提交于 2019-12-13 20:09:17

问题


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


回答1:


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.




回答2:


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);
    }
}


来源:https://stackoverflow.com/questions/979883/postback-problem-for-my-custom-control-load-wizard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!