IPostBackDataHandler problem

Discussion in 'ASP .Net' started by Piotr Nowak, Sep 5, 2007.

  1. Piotr Nowak

    Piotr Nowak Guest

    Hi,

    Im developing a RibbonBar Control in asp.net 1.1 by converting already
    done in asp.net 2.0.
    My problem is that theres no compositecontrol in 1.1. Correct me if im
    wrong, heres what i want to achieve.

    My RibbonButton control is a regular webcontrol. RibbonButton
    instantiates a hiddenfield inside by creating new instance. So we have
    simple situation here wheres RibbonControl that contains hiddenfield
    control inside.
    Note that aps.net 1.1 does not have hidden fields so i created my own
    listed below:

    public class SharedStateHiddenField : WebControl, IPostBackDataHandler
    {
    public string Value
    {
    get { return ViewState["Value"] != null ? (string)ViewState["Value"]
    : string.Empty; }
    set { ViewState["Value"] = value; }
    }

    protected override void AddAttributesToRender(HtmlTextWriter writer)
    {
    writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
    writer.AddAttribute(HtmlTextWriterAttribute.Name, ClientID);
    writer.AddAttribute(HtmlTextWriterAttribute.Value, Value);
    writer.AddAttribute(HtmlTextWriterAttribute.Type, "hidden");
    }

    protected override HtmlTextWriterTag TagKey
    {
    get
    {
    return HtmlTextWriterTag.Input;
    }
    }
    #region IPostBackDataHandler Members

    public void RaisePostDataChangedEvent()
    {

    }

    bool IPostBackDataHandler.LoadPostData(string postDataKey,
    System.Collections.Specialized.NameValueCollection values)
    {
    return LoadPostData(postDataKey, values);
    }
    protected virtual bool LoadPostData(string postDataKey,
    System.Collections.Specialized.NameValueCollection values)
    {
    string val = values[this.ClientID];
    bool changed = false;
    if (val != Value)
    {
    Value = val;
    changed = true;
    }
    return changed;
    }

    #endregion
    }
    }

    So, when i do postback on whatever control on my page, this
    IPostBackDataHandler in my hidden field is not fired !

    i want it to be fired and thats my question, why ?

    Do you possibly know what is wrong ?

    regards, Peter
    Piotr Nowak, Sep 5, 2007
    #1
    1. Advertising

  2. Piotr Nowak

    Smith Guest

    Smith, Sep 5, 2007
    #2
    1. Advertising

  3. Piotr Nowak

    Piotr Nowak Guest

    Smith pisze:
    >> My problem is that theres no compositecontrol in 1.1. Correct me if im
    >> wrong, heres what i want to achieve.

    >
    > Composite controls come from 1.xx . Try this:
    > http://www.microsoft.com/MSPress/books/5728.aspx
    > Cheers
    > Smith
    >
    >


    Ok Found the problem.
    I used clientId instead of uniqueId property, ma fault.

    here's the correct code for hiddenfield control in asp.net 1.1 :)

    public class SharedStateHiddenField : WebControl, IPostBackDataHandler
    {
    public string Value
    {
    get { return ViewState["Value"] != null ? (string)ViewState["Value"]
    : string.Empty; }
    set { ViewState["Value"] = value; }
    }

    protected override void AddAttributesToRender(HtmlTextWriter writer)
    {
    writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
    writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
    writer.AddAttribute(HtmlTextWriterAttribute.Value, Value);
    writer.AddAttribute(HtmlTextWriterAttribute.Type, "hidden");
    }

    protected override HtmlTextWriterTag TagKey
    {
    get
    {
    return HtmlTextWriterTag.Input;
    }
    }
    #region IPostBackDataHandler Members

    public void RaisePostDataChangedEvent()
    {

    }

    bool IPostBackDataHandler.LoadPostData(string postDataKey,
    System.Collections.Specialized.NameValueCollection values)
    {
    return LoadPostData(postDataKey, values);
    }
    protected virtual bool LoadPostData(string postDataKey,
    System.Collections.Specialized.NameValueCollection values)
    {
    string val = values[this.UniqueID];
    bool changed = false;
    if (val != Value)
    {
    Value = val;
    changed = true;
    }
    return changed;
    }

    #endregion
    }
    Piotr Nowak, Sep 5, 2007
    #3
  4. Piotr Nowak

    Mythran Guest

    "Piotr Nowak" <> wrote in message
    news:fblu7v$jtd$...
    > Note that aps.net 1.1 does not have hidden fields so i created my own
    > listed below:



    What do you mean 1.1 doesn't have hidden fields?!? Check out the
    System.Web.UI.HtmlControls namespace and look for the HtmlInputHidden
    control. :)

    HTH,
    Mythran
    Mythran, Sep 5, 2007
    #4
  5. Piotr Nowak

    Piotr Nowak Guest

    Mythran pisze:
    >
    >
    > "Piotr Nowak" <> wrote in message
    > news:fblu7v$jtd$...
    >> Note that aps.net 1.1 does not have hidden fields so i created my own
    >> listed below:

    >
    >
    > What do you mean 1.1 doesn't have hidden fields?!? Check out the
    > System.Web.UI.HtmlControls namespace and look for the HtmlInputHidden
    > control. :)
    >
    > HTH,
    > Mythran
    >
    >


    oh, right :)
    i think i was suggested by some news article saying that asp.net 2.0 has
    some new features like the new HiddenField component.

    anyway, thanks :)
    Piotr Nowak, Sep 6, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper

    Re: Help w/ IPostBackDataHandler

    Showjumper, Jun 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,637
    Showjumper
    Jun 24, 2003
  2. One Handed Man \( OHM - Terry Burns \)

    Custom Control & System.Web.UI.IPostBackDataHandler.LoadPostData

    One Handed Man \( OHM - Terry Burns \), Jun 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,934
    One Handed Man \( OHM - Terry Burns \)
    Jun 17, 2004
  3. Francois
    Replies:
    6
    Views:
    2,833
    Joe Fallon
    Dec 5, 2004
  4. =?Utf-8?B?YnJpYW4ubWlsbHM=?=

    IPostBackDataHandler.LoadPostData

    =?Utf-8?B?YnJpYW4ubWlsbHM=?=, Apr 20, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    3,429
    William F. Robertson, Jr.
    Apr 25, 2005
  5. David.Morales

    problem distinguishing combo null with IPostBackDataHandler

    David.Morales, Feb 28, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    108
    David.Morales
    Feb 28, 2006
Loading...

Share This Page