J
John Wright
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.Controls[1];
txtMultiplier.Attributes.Add("productline",dv["ProductGrouping"].ToString());
txtMultiplier.Attributes.Add("OnChange","SetItemChangedFlag(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
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.Controls[1];
txtMultiplier.Attributes.Add("productline",dv["ProductGrouping"].ToString());
txtMultiplier.Attributes.Add("OnChange","SetItemChangedFlag(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