Question

I am using radcontrols in my porject and i want to restrict the radTextboxes should not allow the Special Characters so i am using script function inside my aspx page it is working properly, But i want to use this in entire project so i want to maintain a javascript file from that i want to use that function so help me on this how to pass textbox id and notification id to function. Here is my code

aspx

script file

function valueChangedHandler(sender, eArgs) {alert("Done");
    var pattern = /^[a-zA-Z0-9\s]*$/;
    var value = sender.get_value();
    var matchArray = value.match(pattern);
    if (matchArray == null) {
        var notification = $find("<%=lblNotification.ClientID %>");
        notification.set_text('Enter AlphaNumerics Only!');
        notification.show();
        sender.clear();
        sender.focus();
        exit();
    }

}

notification code

 <telerik:RadNotification runat="server" BorderColor="Black" BorderStyle="Solid" BackColor="ActiveBorder" BorderWidth="4" EnableRoundedCorners="true" EnableShadow="true" ID="lblNotification" Position="BottomRight" ShowCloseButton="true" Opacity="90" Title="Result" VisibleTitlebar="False">

            </telerik:RadNotification>

above is working properly but i am not getting notification message so tell me how to pass notification id. with a small example.

Était-ce utile?

La solution

You simply can't use server code blocks in an external JS file. They are parsed by the server only in aspx/ascx files. What you can do is to declare a function on the page that has the notification that will return the desired reference:

function getNotification(){
     return $find("<%=lblNotification.ClientID %>");
}

Then the function in your JS file will call this function:

var notification = getNotification();

There are other ways of using ClientIDs in external files, e.g. creating an array in a global variable in the page, but if you do not want to rely on hardcoded IDs they will include code in the page. Well, you can also inject the script from the code-behind, but there isn't much of a difference.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top