This is a migrated thread and some comments may be shown as answers.

Set width in javascript.

1 Answer 159 Views
Input
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 06 Nov 2013, 02:35 AM
There is a radtextbox and a radsearchbox in my aspx page. The Javascript in this page has a getOrder() in which I want to access the width of the textbox and set it to searchbox using style.width. The width of searchbox increases to the stipulated width but the lens symbol position remains unchanged. If I set width in markup it works, but not in JavaScript.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Nov 2013, 08:22 AM
Hi Ben,

Please have a look into the following code I tried for your scenario which works fine at my end. If you set the width using _element.style.width approach, then you should call the repaint() to render the style properly.

ASPX:
<telerik:RadTextBox ID="RadTextBox1" runat="server" Width="400px">
</telerik:RadTextBox>
<br />
<telerik:RadSearchBox ID="RadSearchBox1" runat="server">
</telerik:RadSearchBox>
<br />
<telerik:RadButton ID="RadButton1" runat="server" Text="Set Width to RadSearchBox" AutoPostBack="false"
    OnClientClicked="setSearchBoxWidth">
</telerik:RadButton>

JavaScript:
<script type="text/javascript">
    function setSearchBoxWidth(sender, args) {
        var radtextboxwidth = $find("<%= RadTextBox1.ClientID%>")._element.offsetWidth;
        var radsearchbox = $find("<%= RadSearchBox1.ClientID%>");
        radsearchbox._element.style.width = radtextboxwidth + "px";
        radsearchbox.repaint();
    }
</script>

Thanks,
Shinu.
Tags
Input
Asked by
Ben
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or