Search code examples
asp.netdata-bindingwebforms

asp.net web forms bind only <%# %>


Is here any way of binding <%# Page.ClientID %> without binding Page child controls?

For example:

<%# SomePageProprtyThatReturnsString %>
<someTag:SomeControl ID="SomeControlID" runat="server" OnDataBinding="SomeControlID_DataBinding"></someTag:SomeControl>

If I have following than SomeControlID will be bound on each unwanted post-back

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    DataBind();
}

If I will not bind page on each post back then SomePageProprtyThatReturnsString will not be visible on post-backs


Solution

  • <%# SomePagePropertyThatReturnsString %>
    

    Looks like it might be some public property you've created on the Page itself? If that is the case you can output that property directly without the need for databinding by changing your code:

    <%= this.Page.SomePropertyThatReturnsString %>