2012-08-17 61 views
0

我在我的项目中使用radcontrols,我想限制radTextboxes不应该让特殊字符,所以我使用脚本函数里面我的aspx页面它工作正常,但我想要在整个项目中使用这个,所以我想维护一个JavaScript文件,我想使用该功能,所以帮助我如何通过文本框ID和通知ID来传递函数。这里是我的代码如何查找Radnotification id里面的javascript文件函数

ASPX

脚本文件

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(); 
    } 

} 

通知代码

<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> 

上述工作正常,但我没有得到通知消息,所以告诉我如何传递通知ID。有一个小例子。

回答

0

您根本无法在外部JS文件中使用服务器代码块。它们仅在aspx/ascx文件中被服务器解析。你可以做的是到具有将返回所需的参考通知的页面上声明函数:

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

然后在您的JS文件中的函数将调用这个函数:

var notification = getNotification(); 

有是在外部文件中使用ClientID的其他方式,例如在页面中的全局变量中创建一个数组,但是如果你不想依靠硬编码的ID,他们会在页面中包含代码。那么,你也可以从代码隐藏中注入脚本,但没有太大区别。