This is a migrated thread and some comments may be shown as answers.

Validation in EditItemTemplate

3 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JSON
Top achievements
Rank 1
JSON asked on 22 Mar 2012, 07:23 PM
I am attempting to add a CustomValidator to a control in an EditItemTemplate, but cannot figure out how to get the values of the two objects involved in the OnServerValidate event. Have googled for information half a day with no success.

Based on a value entered in a TextBox with validation, I need to determine if a value exists in a RadDatePicker inside all within an EditItemTemplate. (edit mode)

Thanks,
SteveO...

 

<EditItemTemplate>

 

 

<asp:TextBox ID="nextact" runat="server" onclick="javascript:HighlightRow(this);" Text='<%# Bind("NextAct")%>' Width="20px" Style="text-transform:uppercase" ></asp:TextBox>

 

 

<asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="Next Act Date required" OnServerValidate="NextActDate_Validate" Display="Dynamic" > </asp:CustomValidator>

 

 

</EditItemTemplate>

 


3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 23 Mar 2012, 06:36 AM
Hello,

You can try the following code to access controls in ServerValidate event.
C#:
protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
{
  CustomValidator val = (CustomValidator)source;
  GridEditFormItem item = (GridEditFormItem)val.NamingContainer;
  TextBox txt = (TextBox)item.FindControl("nextact");
  RadDatePicker pkr = (RadDatePicker)item.FindControl("RadDatePicker1");
}

Thanks,
Shinu.
0
JSON
Top achievements
Rank 1
answered on 23 Mar 2012, 02:52 PM
Shinu,

Thank you very much, that did the trick!

SteveO...
0
Shinu
Top achievements
Rank 2
answered on 24 Mar 2012, 09:27 AM
Hi,

Glad to hear that it worked. You are welcome.

Regards,
Shinu
Tags
Grid
Asked by
JSON
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
JSON
Top achievements
Rank 1
Share this question
or