Composite controls and Property Accessors

Discussion in 'ASP .Net Building Controls' started by Sam Samnah, Jun 27, 2005.

  1. Sam Samnah

    Sam Samnah Guest

    I am building a custom control and I need to access the information in the
    hidden field (HtmlInputHidden HIH) so that when a button is pressed the
    information in the hidden field value is returned. Somehow, when the
    submit button is pressed the value in the Hidden field disappears into cyber
    nothing. Please help. This application is supremely important to me.

    Any help is greatly appreciated thank you

    the code is as follows:
    public class FreeForm : WebControl, IPostBackDataHandler
    {
    HtmlGenericControl HGC;
    HtmlInputHidden HIH;
    public FreeForm(): base(HtmlTextWriterTag.Table)
    {}
    public string Text
    {
    get{return HIH.Value;}
    set{HIH.Value=value;}
    }

    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender (e);
    if(!Page.IsClientScriptBlockRegistered("startUp"))
    {
    StringBuilder jsload=new StringBuilder();

    jsload.Append(@"Some javascript not needed here"); // information is
    transfered from the div tag to the hidden tag
    // using client side code.

    string CMSUpReg=jsload.ToString();
    Page.RegisterClientScriptBlock("startUp",CMSUpReg);
    }
    }
    protected override void CreateChildControls()
    {

    Controls.Add(new LiteralControl("<tr bgcolor='#ffffff' height='100%'
    width='100%'>"));
    Controls.Add(new LiteralControl("<td valign='top'>"));

    HIH=new HtmlInputHidden();
    HIH.Attributes.Add("value",Text);
    HIH.Attributes.Add("name",this.UniqueID);
    Controls.Add(HIH);

    HGC=new HtmlGenericControl("div");
    HGC.Attributes.Add("CONTENTEDITABLE","true");
    HGC.Attributes.Add("width","100%");
    HGC.Attributes.Add("height","100%");
    HGC.Attributes.Add("onBlur","moveCurser(" + HIH.UniqueID + ");");
    HGC.Attributes.Add("id","oDiv");
    Controls.Add(HGC);

    Controls.Add(new LiteralControl("</td>"));
    Controls.Add(new LiteralControl("</tr>"));
    base.CreateChildControls ();
    }
    #region IPostBackDataHandler Members

    public event EventHandler TextChanged;
    public void RaisePostDataChangedEvent()
    {
    onTextChanged(new EventArgs());
    }

    protected virtual void onTextChanged(EventArgs e)
    {
    if(TextChanged !=null)
    {
    TextChanged(this, e);
    }
    }
    public bool LoadPostData(string postDataKey,
    System.Collections.Specialized.NameValueCollection postCollection)
    {
    string postedValue=postCollection[postDataKey];
    string val=Text;
    if(val!=postedValue)
    {
    Text=postedValue;
    return true;
    }
    else
    {
    return false;
    }
    }

    #endregion
    }
    [ParseChildren()]
    [PersistChildren(false)]
    public class cToolRow : WebControl
    {
    public cToolCell cCell;
    public cToolRow():base(HtmlTextWriterTag.Tr)
    {}
    protected override void AddAttributesToRender(HtmlTextWriter writer)
    {
    writer.AddAttribute(HtmlTextWriterAttribute.Height,"1");
    base.AddAttributesToRender (writer);
    }
    }
    [ParseChildren()]
    [PersistChildren(false)]
    public class cToolCell : WebControl, INamingContainer
    {
    public cToolCell() : base(HtmlTextWriterTag.Td){}
    protected override void AddAttributesToRender(HtmlTextWriter writer)
    {
    base.AddAttributesToRender (writer);
    }
    }
     
    Sam Samnah, Jun 27, 2005
    #1
    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. sleigh
    Replies:
    1
    Views:
    2,698
    sleigh
    Feb 12, 2004
  2. Mark
    Replies:
    2
    Views:
    664
  3. Andrei Sinelnikov

    Web Custom/Composite controls default property render issue.

    Andrei Sinelnikov, May 7, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    194
    Andrei Sinelnikov
    May 10, 2004
  4. Chad
    Replies:
    0
    Views:
    233
  5. Mike

    Composite vs non composite Controls

    Mike, Mar 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    268
    Sundararajan
    Mar 11, 2005
Loading...

Share This Page