Getting client object within div for any radcontrol!

4 posts, 0 answers
  1. Chetan
    Chetan avatar
    13 posts
    Member since:
    Sep 2012

    Posted 03 Dec 2013 Link to this post

    Is there a way to get the client object of rad control withing the div? I have a div with class="extension" I can get hold of div using jquery. Now I want to $find all different radcontrol in that div and modify using client methods.. .. I cannot use if because they are within listview | raddockzone | custom usercontrol | div with class
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Dec 2013 Link to this post

    Hi Chetan,

    Please have a look into the following code snippet to access the Client Side  object of RadControls with in the div with class.

    ASPX:
    <div class="extension" runat="server">
        <telerik:RadTextBox ID="RadTextBox1" runat="server" Text="Text1">
        </telerik:RadTextBox>
        <telerik:RadButton ID="RadButton1" runat="server" Text="Button1">
        </telerik:RadButton>
    </div>

    JavaScript:
    <script type="text/javascript">
        function pageLoad() {
            var textbox = $find("<%=RadTextBox1.ClientID %>");
            alert("TextBox " + textbox.get_value());
            var button = $find("<%=RadButton1.ClientID %>");
            alert("Button " + button.get_text());
        }
    </script>

    Let me know if you have any concern.
    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chetan
    Chetan avatar
    13 posts
    Member since:
    Sep 2012

    Posted 04 Dec 2013 Link to this post

    Thanks Princy, 
    Is there any other way to get the client object without using the clientID? I dont have accesss to clientID becuase these RadTextBox and RadButton are in userControl for a good reason.
    here is the code snippet:

     
    <div class="extension">
     <uc:UCFormExt runat="server" ID="UCFormExt1" />
    </div>
     

    In usercontrol UCFormExt I have defined textbox, combobox, and radbutton.
    So I cannot use <% =textbox1.ClientID%> because it is repeated on page mulitple times because it is in RadListView!
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Dec 2013 Link to this post

    Hi Chetan,

    Please have a look into the following code snippet to achieve your scenario.

    ASPX:
    <div class="extension">
        <uc1:WebUserControl2 ID="WebUserControl21" runat="server" />
    </div>

    ASCX:
    <telerik:RadListView runat="server" ID="RadListView1" AllowPaging="True" DataKeyNames="CustomerID"
        DataSourceID="SqlDataSource1">
        <LayoutTemplate>
            <table>
                <thead>
                    <tr>
                        <th>
                            CustomerID
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr id="itemPlaceholder" runat="server">
                    </tr>
                </tbody>
            </table>
            </div>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Eval("CustomerID") %>'></asp:Label>
                </td>
                <td>
                    <telerik:RadTextBox ID="CompanyNameTextBox" runat="server" Text='<%# Bind("CompanyName") %>'>
                    </telerik:RadTextBox>
                </td>
            </tr>
        </ItemTemplate>
    </telerik:RadListView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CustomerID], [CompanyName] FROM [Customers]">
    </asp:SqlDataSource>

    ASCX JavaScript:
    <script type="text/javascript">
        function pageLoad() {
            //access the first textbox in the radlistview.
            var textbox = $find('<%=((RadTextBox)RadListView1.Items[0].FindControl("CompanyNameTextBox")).ClientID%>');
        }
    </script>

    Thanks,
    Princy.
Back to Top