So, I'm not so expert, so this is not a complete answer ... From what I see it is not a dynamically created control, I'm sure you mean that the size is dynamic? So how would that change depending on what's inside?
I wrote code with jQuery that gets the width of td and sets a hidden value for it, and then gets the value of this hidden field from asp.net. Perhaps the best ways send value from js to asp.net
One more thing, because of the return mail, I think, try to press the button twice. (Again, someone smarter can answer why this is happening)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="testing._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript" /> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="click" /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:HiddenField ID="hid" runat="server" /> </form> <table> <tr> <td id="image2"> <img src="http://i38.tinypic.com/2el8jfb.jpg" /> </td> </tr> </table> <script type="text/javascript"> $(document).ready( function() { var w = $('#image2').width(); $("#hid").val(w); } ); </script> </body> </html> protected void click(object sender, EventArgs e) { TextBox1.Text = hid.Value; }
I thought of all the servers using the id and runat server controls, but when I access this image using code using imageTD.Width.Value, it turns out 0, maybe someone can understand why this ... .
Hope this helps! =)
source share