【问题标题】:How to find Radnotification id insidet the javascript file function如何在 javascript 文件函数中找到 Radnotification id
【发布时间】:2012-08-17 12:26:41
【问题描述】:

我在我的项目中使用 radcontrols,我想限制 radTextboxes 不应该允许特殊字符,所以我在我的 aspx 页面中使用脚本函数它工作正常,但我想在整个项目中使用它所以我想要要从中维护一个javascript文件,我想使用该功能,所以请帮助我了解如何将文本框ID和通知ID传递给功能。这是我的代码

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。举个小例子。

【问题讨论】:

    标签: javascript asp.net telerik rad-controls


    【解决方案1】:

    您根本不能在外部 JS 文件中使用服务器代码块。服务器仅在 aspx/ascx 文件中解析它们。您可以做的是在页面上声明一个函数,该函数具有将返回所需引用的通知:

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

    那么你的JS文件中的函数会调用这个函数:

    var notification = getNotification();
    

    还有其他在外部文件中使用 ClientID 的方法,例如在页面的全局变量中创建一个数组,但如果您不想依赖硬编码的 ID,它们将在页面中包含代码。好吧,您也可以从代码隐藏中注入脚本,但差别不大。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-03
      • 1970-01-01
      • 2019-03-26
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-30
      相关资源
      最近更新 更多