首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JavaScript不使用RadTextBox

JavaScript不使用RadTextBox
EN

Stack Overflow用户
提问于 2013-10-23 06:51:43
回答 2查看 5.2K关注 0票数 0
代码语言:javascript
复制
 <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">

            function ValidatePhoneNumbers() {

                var phone = document.getElementById('txtPhone1');
                var mobile =document.getElementById('txtPhone2');
                alert(phone.value);
                if ((phone.value == null || phone.value == "") && (mobile.value == null || mobile.value == "")) {
                    alert('something');
                    return false;
                }
                else {
                    alert('something');
                    return true;
                }
           }

        </script>

代码语言:javascript
复制
<tr>
                                        <td>
                                         <label for="txtPhone1">
                                                Phone :</label>
                                        </td>
                                        <td>

                                            <telerik:RadNumericTextBox ID="txtPhone1" runat="server" Text='<%# Bind("Phone_One") %>' Type="Number" Skin="Windows7" CssClass="txt">
                                                     <numberformat allowrounding="false" keepnotroundedvalue="False" GroupSeparator=""></numberformat>
                                            </telerik:RadNumericTextBox>
                                            <asp:CustomValidator ID="rqfldPhone1" runat="server" ControlToValidate="txtPhone1"
                                                Display="Dynamic" ErrorMessage="*" ValidationGroup="Submit" ToolTip="Enter Phone Number"  ></asp:CustomValidator>
                                        </td>

代码语言:javascript
复制
 <telerik:RadButton ID="btnUpdate" runat="server" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                    CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                    Skin="Windows7" ValidationGroup="Submit">

当我在RadButton中添加“RadButton”以调用javaScript中的javaScript (“返回ValidatePhoneNumbers”)时,它显示为NULL为什么?有2个rad文本框txtphone1和txtphone2,实际上我想验证这些文本框,如果任何一个没有被填充,否则我需要显示一个错误/警告消息。请帮帮我

实际上,".value“在javascript (document.GetelementById.value)中没有显示

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-25 07:10:09

当您使用telerik控件时,javascript查找控件和do操作与我们使用普通html和javascript的不同:

找到雷达盒:

代码语言:javascript
复制
$find("<%=RadComboBox1.ClientID %>");//for example

让我们来解决你的问题:

代码语言:javascript
复制
var phone=$find("<%=txtPhone1.ClientID %>");
var mobile=$find("<%=txtPhone2.ClientID %>");
alert(phone.get_value());//use get_value() to get the value of radcombobox
if ((phone.get_value() == null || phone.get_value() == "") && (mobile.get_value() == null ||  mobile.get_value()== "")) {
        alert('something');
        eventArgs.set_cancel(true);
    }
    else {
        alert('something');
    }
}
票数 2
EN

Stack Overflow用户

发布于 2013-10-23 15:14:20

OnClientClicked事件将按名称运行一个函数,其中包含2个参数,这些参数类似于.NET事件处理程序(发送方和eventArgs)使用的参数。Telerik控件不会以与一般return false;对象相同的方式取消该操作,因为它不会取消回发。相反,Telerik在set_cancel参数中提供了一个set_cancel()函数。

代码语言:javascript
复制
function ValidatePhoneNumbers(sender, eventArgs) {
    var phone = document.getElementById('<%= txtPhone1.ClientId %>'); // Corrected as per my comment
    var mobile =document.getElementById('<%= txtPhone2.ClientId %>'); // Corrected as per my comment
    alert(phone.value);
    if ((phone.value == null || phone.value == "") && (mobile.value == null || mobile.value == "")) {
        alert('something');
        eventArgs.set_cancel(true);
    }
    else {
        alert('something');
    }
}

您不需要设置OnClientClicked="return ValidatePhoneNumbers",而是使用OnClientClicking ="ValidatePhoneNumbers"重新注释(参见:http://www.telerik.com/help/aspnet-ajax/button-onclientclicking.html)。

有关客户端事件处理程序的更多信息,请参见:http://demos.telerik.com/aspnet-ajax/menu/examples/programming/clientevents/defaultcs.aspx

如果按钮未设置CausesValidation="True",则验证器应在按下按钮时触发,并可能考虑使用RequiredFieldValidator以确保在回发之前填充该按钮。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19534754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档