Custom TextBox with custom attributes and properties question

Ask a Question related to ASP.NET, Design and Development.

  1. #1

    Default Custom TextBox with custom attributes and properties question

    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
    value.

    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:

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

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

    //control[1] is the text box...
    UtilityControls.DirtyTextBox txtMultiplier =
    (UtilityControls.DirtyTextBox)objArgs.Item.Control s[1];
    txtMultiplier.Attributes.Add("productline",dv["ProductGrouping"].ToString());
    txtMultiplier.Attributes.Add("OnChange","SetItemCh angedFlag(this);");
    //used before custom control defaulted IsDirty to
    false
    //txtMultiplier.Attributes.Add("IsDirty","false");
    //need to have txtMultiplier.IsDirty = false; show up
    as attribute

    }

    }

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

    Regards,
    John Wright
    John Wright Guest

  2. Similar Questions and Discussions

    1. Making Custom Control Properties Visible in Visual Studio's Properties Palette
      I am learning how to use the System.ComponentModel class in VB.NET so that I can add my ASP.NET controls to Visual Studio .NET 2003. I have managed...
    2. Custom attributes/properties at design time (serialization?)
      OK. here's what I want to do. I have a text editor control that I created. I also have a seriedsof palette controls that I have created for use...
    3. XmlAttributeOverrides with Custom Attributes?
      Dear All, I really enjoy the cleaness of using the build in Serialization of .NET. Now I am sitting with a dillema. I need to limit the Properties...
    4. XHTML and custom attributes
      I'm planning my strategy to be XHTML ready for "Whidbey". My ASP.NET controls have a lot of client-side scripting. Sometimes I pass along custom...
    5. Custom Component and Custom Textbox binding
      Hi, I am trying to accomplish the following. Here is what I want to do: 1. Drop a custom business object component onto the design surface...
  3. #2

    Default Re: Custom TextBox with custom attributes and properties question

    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;

    }

    [System.Security.Permissions.PermissionSet(System.S ecurity.Permissions.SecurityAction.Demand,
    Name="FullTrust")]
    protected override void AddAttributesToRender(HtmlTextWriter writer)
    {

    writer.AddAttribute("IsDirty", IsDirty.ToString());
    base.AddAttributesToRender(writer);
    }





    //The IsDirty property.
    public virtual bool IsDirty
    {
    get
    {
    return _dirty;
    }
    set
    {
    _dirty = value;
    }
    }
    }
    }
    John Wright Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139