I have a composite control where I'm adding a LinkButton
dynamically. This control is inside of an UpdatePanel
.
If I set the text of the LinkButton
to something simple, just text (i.e. click here to edit) then it does as intended and I'm able to asynchronously handle the request.
However, if I attempt to use any html markup at all (i.e. <span class="fa fa-edit"></span>
) as the text, it still works but causes a full page refresh.
This is incredibly confusing and I simply don't understand why html markup is causing a post-back but text is not.
Example trimmed down:
Public Class LinkBase
Inherits CompositeControl
Implements INamingContainer
Private ReadOnly _linkButton As LinkButton = New LinkButton()
Protected Overrides Sub CreateChildControls()
Controls.Clear()
'_linkButton.Text = "Click here to edit" <-- works
_linkButton.Text = "<span class='fa fa-edit'></span>" <-- causes refresh
Controls.Add(_linkButton)
MyBase.CreateChildControls()
End Sub
End Class
Update
My custom control looks like this:
<custom:EditLink Text="Edit Me" />
Which renders as:
<a href="javascript:__doPostBack('shortened_ListView$l00','')">
Edit Me
</a>
And if I use:
<custom:EditLink Text='<span class="fa fa-edit"></span>' />
It renders as:
<a href="javascript:__doPostBack('shortened_ListView$l00','')">
<span class="fa fa-edit"></span>
</a>
This is as expected, as the Text
property is the default inner property, so you can set it directly (i.e. Text) or use the inner content. Now the reason I'm setting it directly is because I technically have other child controls within my <custom:EditLink>
that serve other purposes.
But again, when I use html it causes a page refresh. When I do not, such as "Edit Me" it uses the ajax method of update panel.