telerik asp.net控制清除客户端

时间:2021-12-20 15:33:25

Hi I'm using telerik rad controls for asp.net I have to clear the inputs with javascript; but telerik controls (radcombobox e.g.) generates a huge markup so how to clear telerik controls on a page in client-side?

嗨,我正在使用asp.net的telerik rad控件我必须用javascript清除输入;但是telerik控件(例如radcombobox)会生成一个巨大的标记,以便如何清除客户端页面上的telerik控件?

thnx

5 个解决方案

#1


I have very simple working example. I hope this would give you some ideas on how to proceed. I have done some clearing for the textboxes.

我有一个非常简单的工作示例。我希望这会给你一些关于如何进行的想法。我已经为文本框做了一些清理工作。

 <Items>
        <telerik:RadComboBoxItem Text="Oragnes" Value="1" />
 </Items>
 <Items>
        <telerik:RadComboBoxItem Text="Apples" Value="2" />
 </Items>
 <Items>
        <telerik:RadComboBoxItem Text="Bananas" Value="" />
 </Items>

</telerik:RadComboBox>
  &nbsp;
<telerik:RadTextBox ID="rdTextBox" runat="server" ></telerik:RadTextBox>
&nbsp;
<telerik:RadTextBox ID="RadTextBox1" runat="server" ></telerik:RadTextBox>
&nbsp;
<telerik:RadTextBox ID="RadTextBox2" runat="server" ></telerik:RadTextBox>
      <br />
<input type="button" onclick="ClearRadControls()" value="Clear Rad Controls" />

<script language="javascript" type="text/javascript">

function   ClearRadControls()
{
    var radControl1TextBox = document.getElementById("<%=rdTextBox.ClientID  %>" + "_text");
    var RadTextBox1 = document.getElementById("<%=RadTextBox1.ClientID  %>" + "_text");
    var RadTextBox2 = document.getElementById("<%=RadTextBox2.ClientID  %>" + "_text");
    radControl1TextBox.value   = '';
    RadTextBox1.value = "";
    RadTextBox2.value = "";
}

</script>

#2


telerik has somewhat useful help documentation for the asp.net radcontrols here:

telerik有一些有用的asp.net radcontrols帮助文档:

http://www.telerik.com/help/aspnet-ajax/introduction.html

To answer your question for the combobox:

要回答关于组合框的问题:

Use telerik's $find function to return the telerik object of the control. Then you can use the client side functions built in to the controls.

使用telerik的$ find函数返回控件的telerik对象。然后,您可以使用内置于控件的客户端功能。

function ClearSelection() {
    var combo = $find("<%= yourCombo.ClientID %>");
    combo.clearSelection(); 
  }

http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcombobox.html

#3


This could be off topic but the JS framework Dojo could be of help . See this code I use to uncheck all my checkboxes. These controls are all generated on the fly.

这可能是偏离主题,但JS框架Dojo可能会有所帮助。看到我用来取消选中所有复选框的代码。这些控件都是动态生成的。

> // Uncheck the children
>                   dojo.forEach(
>                       dojo.query("input[type='checkbox']",
> subList),
>                       function(checkboxTag) {
>                           checkboxTag.checked = false;
>                       }
>                   );

#4


I found a js solution over a blog as..

我在博客上发现了一个js解决方案。

on sample code with I searched up for named "sampleDivInGrid" div item inside a RadGrid..

我在示例代码中搜索了RadGrid中名为“sampleDivInGrid”的div项目。

                 function GetServerElement(serverID, tagName) {
                     if (!tagName)
                         tagName = "*"; //* means all elements  
//i give here the Grid clientID which is owner of the control that we search 
                     var grid = document.getElementById("<%=grdItems.ClientID %>");
                     var elements = grid.getElementsByTagName(tagName);
                     for (var i = 0; i < elements.length; i++) {
                         var element = elements[i];
                         if (element.id.indexOf(serverID) >= 0)
                             return element;
                     }
                 }


                 function OnClientIndexChanged(sender, eventArgs) {

                     var itm = GetServerElement("sampleDivInGrid", "div");
                     var item = eventArgs.get_item();
                     var itmTxt = item.get_text();
                     alert(itmTxt);
                 }

#5


You can use telerik's $find function to return the telerik object of the control.

您可以使用telerik的$ find函数返回控件的telerik对象。

<script type="text/javascript">

    function Something() {
        //...
        $find("<%= yourCombo.ClientID %>").clearSelection();
        //... 
    }
</script>

telerik has somewhat useful help documentation for the asp.net radcontrols here:

telerik有一些有用的asp.net radcontrols帮助文档:

http://www.telerik.com/help/aspnet-ajax/introduction.html

http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcombobox.html

#1


I have very simple working example. I hope this would give you some ideas on how to proceed. I have done some clearing for the textboxes.

我有一个非常简单的工作示例。我希望这会给你一些关于如何进行的想法。我已经为文本框做了一些清理工作。

 <Items>
        <telerik:RadComboBoxItem Text="Oragnes" Value="1" />
 </Items>
 <Items>
        <telerik:RadComboBoxItem Text="Apples" Value="2" />
 </Items>
 <Items>
        <telerik:RadComboBoxItem Text="Bananas" Value="" />
 </Items>

</telerik:RadComboBox>
  &nbsp;
<telerik:RadTextBox ID="rdTextBox" runat="server" ></telerik:RadTextBox>
&nbsp;
<telerik:RadTextBox ID="RadTextBox1" runat="server" ></telerik:RadTextBox>
&nbsp;
<telerik:RadTextBox ID="RadTextBox2" runat="server" ></telerik:RadTextBox>
      <br />
<input type="button" onclick="ClearRadControls()" value="Clear Rad Controls" />

<script language="javascript" type="text/javascript">

function   ClearRadControls()
{
    var radControl1TextBox = document.getElementById("<%=rdTextBox.ClientID  %>" + "_text");
    var RadTextBox1 = document.getElementById("<%=RadTextBox1.ClientID  %>" + "_text");
    var RadTextBox2 = document.getElementById("<%=RadTextBox2.ClientID  %>" + "_text");
    radControl1TextBox.value   = '';
    RadTextBox1.value = "";
    RadTextBox2.value = "";
}

</script>

#2


telerik has somewhat useful help documentation for the asp.net radcontrols here:

telerik有一些有用的asp.net radcontrols帮助文档:

http://www.telerik.com/help/aspnet-ajax/introduction.html

To answer your question for the combobox:

要回答关于组合框的问题:

Use telerik's $find function to return the telerik object of the control. Then you can use the client side functions built in to the controls.

使用telerik的$ find函数返回控件的telerik对象。然后,您可以使用内置于控件的客户端功能。

function ClearSelection() {
    var combo = $find("<%= yourCombo.ClientID %>");
    combo.clearSelection(); 
  }

http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcombobox.html

#3


This could be off topic but the JS framework Dojo could be of help . See this code I use to uncheck all my checkboxes. These controls are all generated on the fly.

这可能是偏离主题,但JS框架Dojo可能会有所帮助。看到我用来取消选中所有复选框的代码。这些控件都是动态生成的。

> // Uncheck the children
>                   dojo.forEach(
>                       dojo.query("input[type='checkbox']",
> subList),
>                       function(checkboxTag) {
>                           checkboxTag.checked = false;
>                       }
>                   );

#4


I found a js solution over a blog as..

我在博客上发现了一个js解决方案。

on sample code with I searched up for named "sampleDivInGrid" div item inside a RadGrid..

我在示例代码中搜索了RadGrid中名为“sampleDivInGrid”的div项目。

                 function GetServerElement(serverID, tagName) {
                     if (!tagName)
                         tagName = "*"; //* means all elements  
//i give here the Grid clientID which is owner of the control that we search 
                     var grid = document.getElementById("<%=grdItems.ClientID %>");
                     var elements = grid.getElementsByTagName(tagName);
                     for (var i = 0; i < elements.length; i++) {
                         var element = elements[i];
                         if (element.id.indexOf(serverID) >= 0)
                             return element;
                     }
                 }


                 function OnClientIndexChanged(sender, eventArgs) {

                     var itm = GetServerElement("sampleDivInGrid", "div");
                     var item = eventArgs.get_item();
                     var itmTxt = item.get_text();
                     alert(itmTxt);
                 }

#5


You can use telerik's $find function to return the telerik object of the control.

您可以使用telerik的$ find函数返回控件的telerik对象。

<script type="text/javascript">

    function Something() {
        //...
        $find("<%= yourCombo.ClientID %>").clearSelection();
        //... 
    }
</script>

telerik has somewhat useful help documentation for the asp.net radcontrols here:

telerik有一些有用的asp.net radcontrols帮助文档:

http://www.telerik.com/help/aspnet-ajax/introduction.html

http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcombobox.html