Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I click on btnWidth the width and height are only temporary.

How do I make them permenant?
JavaScript
<script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
 <script type="text/javascript">
     $(document).ready(function () {
         $("#<%= btnWidth.ClientID %>").click(function () {
             $(".txt").each(function () {
                 $(this).width(200);
                 $(this).height(200);
             });
         });
     });
 </script>

 <asp:TextBox Class="txt" ID="txtone" runat="server">
 <asp:TextBox Class="txt" ID="txttwo" runat="server">
 <asp:TextBox Class="txt" ID="txtthree" runat="server">
 <asp:Button ID="btnWidth" runat="server" Text="Equal Width" />
Posted
Updated 14-Aug-14 1:40am
v3
Comments
Thanks7872 14-Aug-14 7:47am    
What do you mean by temporary and permenant? I suspect you mean that once you click button and set width. Then after postback the width is set to default,right?

Add s style attribute to elements you want as static. No need to set by using jQuery
C#
<asp:button style="width:200px;height:200px;" id="btnWidth" runat="server" text="Equal Width" xmlns:asp="#unknown" />


if you want to change the height and weight when button click you should do this programmatically like you already done.

Hope this helps
 
Share this answer
 
I'm reading a lot into your question, since the question itself wasn't clear. But hopefully this is what you are looking for. My guess is that you want the buttons to be equal widths, but not hard-coded widths.

Here's a function to set them all to match the widest one, each time the page loads:
JavaScript
$(function () {
    var maxWidth = 0;
    $('.txt').each(function () {
        maxWidth = Math.max($(this).width(), maxWidth);
    });
    $('.txt').width(maxWidth);
});

This ensures that all buttons are the same width, but the minimum width necessary to fit the widest text.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900