From: Ujjaval S. <uj...@gm...> - 2006-06-18 06:06:32
Attachments:
DataList.aspx
|
Hello everyone, I was looking at the DataList.aspx example in new Anthem.NET .NET 2.0 examples. I want to use validation control in DataList control. So, I've put it inside <EditItemTemplate> of DataList control.I've also specified validation group. But it doesn't work. Any suggestions on how to make validation control work in DataList control. Below is part of the code where I've made changes for adding validation control: <EditItemTemplate> Name: <asp:TextBox ID="name" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "name") %>' /> <br /> Validation Message: <asp:RegularExpressionValidator ID="nameValidation" ValidationGroup="nametest" runat="server" ErrorMessage="ONLY ENTER NAME" ControlToValidate="name" ValidationExpression="^[a-zA-Z'.\s]{1,10}$" /> <br /> Birthdate: <asp:TextBox ID="birthdate" runat="server" Text='<%# ((DateTime)DataBinder.Eval(Container.DataItem, "birthdate")).ToShortDateString() %>' /> <br /> <anthem:LinkButton ID="update" runat="server" CausesValidation="true" ValidationGroup="nametest" CommandName="Update" Text="Update" /> <anthem:LinkButton ID="cancel" runat="server" CommandName="Cancel" Text="Cancel" /> </EditItemTemplate> I guess everyone has Anthem.NET examples for .NET 2.0. Just in case if someone don't have, I've attached the file with this mail. Thanks in advance, Ujjaval -- Ujjaval Suthar Mobile : +61 - 0431 152 757 |
From: Ujjaval S. <uj...@gm...> - 2006-06-18 06:17:30
|
Hello everyone, I was looking at the DataList.aspx example in new Anthem.NET .NET 2.0 examples. I want to use validation control in DataList control. So, I've put it inside <EditItemTemplate> of DataList control.I've also specified validation group. But it doesn't work. Any suggestions on how to make validation control work in DataList control. Below is part of the code where I've made changes for adding validation control: <EditItemTemplate> Name: <asp:TextBox ID="name" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "name") %>' /> <br /> Validation Message: <asp:RegularExpressionValidator ID="nameValidation" ValidationGroup="nametest" runat="server" ErrorMessage="ONLY ENTER NAME" ControlToValidate="name" ValidationExpression="^[a-zA-Z'.\s]{1,10}$" /> <br /> Birthdate: <asp:TextBox ID="birthdate" runat="server" Text='<%# ((DateTime)DataBinder.Eval(Container.DataItem, "birthdate")).ToShortDateString() %>' /> <br /> <anthem:LinkButton ID="update" runat="server" CausesValidation="true" ValidationGroup="nametest" CommandName="Update" Text="Update" /> <anthem:LinkButton ID="cancel" runat="server" CommandName="Cancel" Text="Cancel" /> </EditItemTemplate> I guess everyone has Anthem.NET examples for .NET 2.0. Just in case if someone need the full code for that page, let me know so that I can copy and send it. I tried to attach aspx file with this mail, but I had an error message from admin; so sent this message without the whole code. Thanks in advance, Ujjaval -- Ujjaval Suthar Mobile : +61 - 0431 152 757 |
From: Andy M. <am...@st...> - 2006-06-18 16:17:21
|
I'm not sure why the client side validation is not running, but you can (should) also run the validation on the server by wrapping the update inside of a check for IsValid like so: void dataList_UpdateCommand(object sender, DataListCommandEventArgs e) { if (IsValid) { string name = ((System.Web.UI.WebControls.TextBox)e.Item.FindControl("name")).Text; string birthdate = ((System.Web.UI.WebControls.TextBox)e.Item.FindControl("birthdate")).Text; TestData.Rows[e.Item.ItemIndex]["name"] = name; TestData.Rows[e.Item.ItemIndex]["birthdate"] = DateTime.Parse(birthdate); dataList.EditItemIndex = -1; BindList(); } } Andy Miller |
From: Andy M. <am...@st...> - 2006-06-18 16:24:18
|
Now I see it. Because you are adding the validation control during a callback, new javascript is added to the page during the callback. Normally Anthem.Manager ignores the scripts on the page. But you can tell it to include the scripts in the callback response like so: void dataList_EditCommand(object sender, DataListCommandEventArgs e) { dataList.EditItemIndex = e.Item.ItemIndex; BindList(); Anthem.Manager.IncludePageScripts = true; } Andy Miller |