Autopostback for Textbox in a DataList

M

milbrand

I have a textbox in a datalist that I need an auto postback on. To
complicate matters, I have a javascript on this textbox as well. I am
having two issues. 1) I am only able to get the textbox to fire the
autopostback when the field is blank and 2) I do not know where to
capture the autopostback in the code behind when it happens.

Thanks for your help. Here are some examples of my code (simplified
for this post):

ASPX Page:
<script type="text/javascript">
function validatethisdecimal(i, cssclass)
{
if(i.value.length>0) {
i.value = i.value.replace(/[^\d\.]+/g, '');
}
if(i.value.length>0) {
i.className='normal';
}
else
{
i.className=cssclass;
}
return true;
}
</script>
..
..
..
<asp:datalist id="DL_Principal" runat="server" Width="100%"
OnItemCommand="Principal_ItemCommand"
OnItemDataBound="Principal_DataBound">
<ItemTemplate>
<asp:textbox id="tb_principalname" runat="server" MaxLength="100"
Width="200px" CssClass="required" text='<%#DataBinder.Eval
(Container.DataItem, "PName")%>'></asp:textbox>
<asp:textbox id="tb_perown" runat="server" MaxLength="6" Width="50px"
CssClass="required" AutoPostBack="True" text='<%#DataBinder.Eval
(Container.DataItem, "PPer")%>'></asp:textbox>
</ItemTemplate>
</asp:datalist>


Code Behind (C#)


public void Principal_DataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)
{
if((e.Item.ItemType == ListItemType.AlternatingItem) ||
(e.Item.ItemType == ListItemType.Item))
{
DataListItem dItem = e.Item;

tb = (TextBox)dItem.FindControl("tb_perown");
tb.Attributes.Add("onKeyup", "validatethisdecimal(this,
'required');");

if(tb.Text.ToString().Length > 0)
{
tb.CssClass = "normal";
}
}
}

//This does not fire on the autopostback
public void Principal_ItemCommand(Object sender,
DataListCommandEventArgs e)
{
DataListItem dItem = e.Item;

if((e.Item.ItemType == ListItemType.AlternatingItem) ||
(e.Item.ItemType == ListItemType.Item))
{
.
.
.
}
}

//This also does not fire on the autopostback
private void DL_Principal_SelectedIndexChanged(object sender,
System.EventArgs e)
{
TextBox tb = (TextBox)sender;
DataListItem dItem = (DataListItem)tb.Parent.Parent;
.
.
.
}
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top