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

[Solved] CustomValidator -reference

3 Answers 180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robin Lilly
Top achievements
Rank 1
Robin Lilly asked on 02 Apr 2008, 08:54 PM

Protected Sub CustomValidator1_ServerValidate(ByVal [source] As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)

Dim myGrid As RadGrid = CType(source, CustomValidator).Parent.Parent

To get the reference to the radgrid from the Edit Form the above reference in Prometheus now gets Telerik.Web.UI.GridTableRow and not the RadGrid reference.

What is the correct syntax to get to the RadGrid to handle CustomValidators to find multiple controls within Prometheus?

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 03 Apr 2008, 06:40 AM
Hi Robin,

I'm afraid that this code will not return the grid in both "Prometheus" and "Classic" version. You can try this instead:

Dim myGrid As RadGrid = CType(CType(source, CustomValidator).Parent.Parent, GridItem).OwnerTableView.OwnerGrid

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Robin Lilly
Top achievements
Rank 1
answered on 08 Apr 2008, 11:57 PM
Vlad,

That isn't the correct syntax. I have a demo to show you this error - I can email to you. Below are key code elements.

You get the following:
Unable to cast object of type 'Telerik.Web.UI.GridTableRow' to type 'Telerik.Web.UI.GridItem'.

Robin

Protected Sub CustomValidator1_ServerValidate(ByVal [source] As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)

Dim myGrid As RadGrid = CType(CType(source, CustomValidator).Parent.Parent, GridItem).OwnerTableView.OwnerGrid

args.IsValid =

False

CustomValidator1.ErrorMessage =

"<br>Some ERROR "

End Sub

....

<

telerik:GridTemplateColumn

HeaderText="CompanyName" UniqueName="CompanyName" >

<EditItemTemplate>

<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind( "CompanyName" ) %>'></asp:TextBox>

<asp:CustomValidator ID="CustomValidator1" runat="server" Display="Dynamic" OnServerValidate="CustomValidator1_ServerValidate"

ErrorMessage="</br>Only one Project Number or Job Number can be selected."></asp:CustomValidator>

</EditItemTemplate>

<ItemTemplate><%#DataBinder.Eval(Container.DataItem, "CompanyName")%>

</ItemTemplate>

</telerik:GridTemplateColumn>

0
Ves
Telerik team
answered on 11 Apr 2008, 12:19 PM
Hello Robin,

Indeed, this code might depend on the EditMode -- InPlace or EditForms. However, you can use the following line and it will not depend on this:

Dim myGrid As RadGrid = CType(CType(source, CustomValidator).NamingContainer), GridItem).OwnerTableView.OwnerGrid

Hope this helps.

Regards,
Ves
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Robin Lilly
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Robin Lilly
Top achievements
Rank 1
Ves
Telerik team
Share this question
or