Custom TextBox with custom attributes and properties question

Discussion in 'ASP .Net Building Controls' started by John Wright, Feb 27, 2004.

  1. John Wright

    John Wright Guest

    I have an webform that has a datarepeater on it. In that repeater I'm
    binding some data and I have put a textbox control in there. On the
    OnItemDataBound method of the repeater I have cast the controls
    collection index back to a textbox and added an attribute called
    "IsDirty" which is set to false. Once the page loads I have the
    onchange event call a javascript function that changes the attribute
    "IsDirty" to true. Everything up until now works like a charm.
    However when the page posts back I am trying to iterate over the
    repeater items collection and get the IsDirty value. This still shows
    up as false, and I have verified that the javascript does change the

    My next though was to create a custom control textbox with a IsDirty
    boolean property. That doesn't expose as an attribute. I am looking
    for a way to expose a custom property as an attribute on a custom
    control. Anyone know how I can do this?

    Some code to reference:

    protected void repeaterDataBound(object sender,
    System.Web.UI.WebControls.RepeaterItemEventArgs objArgs)
    ListItemType objItemType = (ListItemType)objArgs.Item.ItemType;

    if ((objItemType == ListItemType.Item)||(objItemType ==
    DataRowView dv = (DataRowView)(objArgs.Item.DataItem);

    //control[1] is the text box...
    UtilityControls.DirtyTextBox txtMultiplier =
    //used before custom control defaulted IsDirty to
    //need to have txtMultiplier.IsDirty = false; show up
    as attribute



    function SetItemChangedFlag(obj)
    var vAttrValue = new String;
    vAttrValue = obj.getAttribute('IsDirty');
    if(vAttrValue.toLowerCase() == false){
    vAttrValue = true;
    //alert("The IsDirty Value is = " + obj.getAttribute('IsDirty'));

    John Wright
    John Wright, Feb 27, 2004
    1. Advertisements

  2. John Wright

    John Wright Guest

    What I have done now is to create a class that derives from the
    TextBox class. In there I have done an override on the
    AddAttributesToRender method (see code below). What I still can't
    figure out is how to I get my control to read back the attributes
    collection and set the IsDirty property equal to the IsDirty
    Attribute. This way when javascript changes the value of the
    attribute it will be recognized when the page renders on a postback.

    using System;
    using System.IO;
    using System.Text;
    using System.Web.UI;

    namespace UtilityControls
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public class DirtyTextBox : System.Web.UI.WebControls.TextBox
    private bool _dirty;

    public DirtyTextBox()

    _dirty = false;


    protected override void AddAttributesToRender(HtmlTextWriter writer)

    writer.AddAttribute("IsDirty", IsDirty.ToString());

    //The IsDirty property.
    public virtual bool IsDirty
    return _dirty;
    _dirty = value;
    John Wright, Mar 1, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.