IPostBackDataHandler problem

P

Piotr Nowak

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
 
P

Piotr Nowak

Smith pisze:
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
}
 
M

Mythran

Piotr Nowak said:
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
 
P

Piotr Nowak

Mythran pisze:
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 :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,734
Latest member
manin

Latest Threads

Top