0

I am using telerik RadTextBox inside asp.net User Control page.

I have writen below Jquery validation code inside main content page as shown below, I am trying to set RadText box name attribute as static inside User Control so that I can use it in Main Content page.

User Control page

<telerik:RadTextBox ID="txtProductPrice" ClientID="txtProductPrice" 
runat="server" ClientIDMode="Static" />

Main Content Page:

    $("#aspnetForm").validate({
        rules: {
            ctl00$ContentPlaceHolder1$ucUserInfoI$txtProductPrice: {
                required: true,
                number: true,
                maxlength: 5            
            },
        }
    });

I have used dynamically generated name attribute to validate the textbox, which looks ugly.

Since RadTexBox is in UserControl page , I am not able to use RadTexBox with UniqueID in main content page as below:

  $("#aspnetForm").validate({
        rules: {
            <%=txtProductPrice.UniqueID %>:{
                required: true,
                number: true,
                maxlength: 5
            },
        }
    });

Any idea how to I can use RadTexBox with UniqueID in main content page ?

Any help would be great.

Shaiju T
  • 6,201
  • 20
  • 104
  • 196
  • 1
    Unobtrusive Validation enabled? – Sparky Mar 28 '19 at 21:55
  • *"So Is there any neat and shorter way to use name attribute inside Main Content page"* ~ What are you asking? The plugin's parameter **MUST** match the actual rendered `name` attribute. If the `name` attribute is not neat and short, then you need blame ASP. – Sparky Mar 28 '19 at 21:57

1 Answers1

1

These steps can prove helpful to you:

1. For client-side logic, you can try using <%=txtProductPrice.ClientID %> instead of UniqueID.

2. Telerik controls are complex server and script controls and you should not use ClientIDMode="Static" with them. Details

3. Make sure you have the following setting in your web.config file as suggested by Sparky:

<appSettings> 
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>

    Here are some Details and More Details.

4. You can always use the $telerik.findControl method to manually access the RadTextBox and execute your custom logic. Details

Eyup Yusein
  • 381
  • 3
  • 8