English 中文(简体)
保持习俗关系。 净控制
原标题:Persisting state of custom ASP.Net control
  • 时间:2011-11-09 23:08:46
  •  标签:
  • asp.net

我有某种习俗控制,这种控制在某种程度上影响在伙伴关系中建立起来。 净检查箱控制。 关于病情,我产生UL>LI>Check Box#custom 建立在数据来源基础上的Id结构正在得到控制。

我最大的难题是,即使输入的超文本内容在网页上公布,但在提交网页时,请求。 表格收集没有与这些投入相关的数据。

So, my question is this: Once a PostBack is triggered, is there a way to get the inputs checked by the user?

Thanks in advance, Kali

最佳回答

通常,海关服务器的控制将采用<代码>SaveViewState、LoadViewStateTrackViewState管理控制状态的方法。

I don t know how you re control is built so I can t give you the exact code, but here s an example of those methods being used in a control that I created:

protected override void LoadViewState(object savedState)
{
    if (savedState != null)
    {
        object[] state = (object[])savedState;

        if (state[0] != null)
            base.LoadViewState(state[0]);
        if (state[1] != null)
            ((IStateManager)ItemStyle).LoadViewState(state[1]);
        if (state[2] != null)
            ((IStateManager)headerStyle).LoadViewState(state[2]);
        if (state[3] != null)
            ((IStateManager)AlternatingItemStyle).LoadViewState(state[3]);
    }
}

protected override object SaveViewState()
{
    object[] state = new object[4];

    state[0] = base.SaveViewState();
    state[1] = itemStyle != null ? ((IStateManager)itemStyle).SaveViewState() : null;
    state[2] = headerStyle != null ? ((IStateManager)headerStyle).SaveViewState() : null;
    state[3] = alternatingItemStyle != null ? ((IStateManager)alternatingItemStyle).SaveViewState() : null;

    return state;
}

protected override void TrackViewState()
{
    base.TrackViewState();

    if (itemStyle != null)
        ((IStateManager)itemStyle).TrackViewState();
    if (headerStyle != null)
        ((IStateManager)headerStyle).TrackViewState();
    if (alternatingItemStyle != null)
        ((IStateManager)alternatingItemStyle).TrackViewState();
}

除上述方法外,如果你想要从<代码>上重载信息,请<>/代码>标的,你可以执行<代码>。 缩略语

public virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
    string somePostedValue = postCollection["SomePostedValue"];
    string anotherPostedValue = postCollection["AnotherPostedValue"];
}

public virtual void RaisePostDataChangedEvent()
{

}
问题回答

正如詹姆斯正确指出的那样,这是一页生命周期的问题。

我最初做的是,用书面写写给吉大不列颠及北爱尔兰王国,写上UL>LI>Render方法投入结构。 虽然这种方法实际上产生了预期的超文本,但在收回时,价调汇率财产并未收回任何已核实的投入。

What I ve end up doing was to create the controls on CreateChildControls using Html Server Controls. This way, I was able to retrieve the information I was looking for from the FORM collection.

此外,正如詹姆斯在其答复中指出的,为了坚持国家的要求,洛德文南和“拯救儿童”方法必须优先于。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签