Wednesday, March 28, 2012

Linebreak appears after update panel submits

I wrote a control that would allow a user to click on a label, and then edit it the value, and send back the new value to the server via an update panel.

However, the first time the value is sent to the server, a line break appears right above the text box, i dont think this is a css error, i can't seem to figure out what is causing it by examining the DOM. This only appears in IE, not Firefox, Any ideas?

Here's the mark up for the Control

<%@dotnet.itags.org. Control Language="VB" AutoEventWireup="false" CodeFile="QuickEditLabel.ascx.vb" Inherits="QuickEditLabel" %><script type="text/javascript"> function<%=Me.hidCurrentFileId.ClientID%>updateNumber(param) { var hiddenField = document.getElementById("<%=hidCurrentFileId.ClientID%>"); hiddenField.value = param; __doPostBack('<%=hidCurrentFileId.ClientID%>',''); } function QuickEditSwap(hideMe, showMe) { showMe.style.display = 'none'; hideMe.style.display = 'inline'; }</script><asp:HiddenField ID="hidCurrentFileId" runat="server" Value="" /><asp:UpdatePanel ID="updPanel" UpdateMode="Conditional" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="hidCurrentFileId" EventName="ValueChanged" /> </Triggers> <ContentTemplate>   <asp:Label ID="Label1" runat="server" CssClass="QuickEditText" ToolTip="Click to Edit"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" CssClass="QuickEditTextBox" Width="93px"></asp:TextBox> </ContentTemplate></asp:UpdatePanel>

Here's the Code behind for the control

PartialClass QuickEditLabelInherits System.Web.UI.UserControlPrivate myTextAs String Public Property Text()Get Return myTextEnd Get Set(ByVal value) myText = valueEnd Set End Property Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.LoadIf Not IsPostBackThen Me.Text ="33"Else Me.Text =Me.TextBox1.TextEnd If Me.TextBox1.Attributes.Add("onchange",Me.hidCurrentFileId.ClientID +"updateNumber(getElementById('" + Me.TextBox1.ClientID + "').value)") Me.Label1.Attributes.Add("onclick", "QuickEditSwap(getElementById('" + Me.TextBox1.ClientID + "'), getElementById('" + Me.Label1.ClientID + "'))")End Sub Protected Sub Page_PreRender(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.PreRenderMe.Label1.Text =Me.TextMe.TextBox1.Text =Me.TextEnd SubEnd Class

Here's the css i'm using for the control

 .QuickEditText {font-family: Verdana;} .QuickEditText:hover {text-decoration: underline; font-family: Verdana; cursor: pointer} .QuickEditTextBox {display: none; font-family:Verdana;}

Thanks in advance for any suggestions,

This is happening because of the default setting of the UpdatePanel's RenderMode property - which will render its contents into a <div> the first time. Try changing it to "Inline" so that it will instead render a <span> element.

No comments:

Post a Comment