ASP.NET Usercontrol Property value does not run <%= markup

吃可爱长大的小学妹 提交于 2019-12-25 08:57:48

问题


Well i have a usercontrol with a property "ClientScript" and in the aspx file where i use the usercontrol i set the value to =document.getElementsByName('<%=ReportViewer1.ClientId %>$ctl01$ctl07$ctl00$ctl00$ctl00')[0].click(); return false;

the problem here is that the is litterly passed to the property and not parsed first and replaced by the ClientID..

I had the same clientscript applied to a buttons OnClientClick and there it worked...

Must i apply some sort of attribute to the property to get this working?

here is my code:

Usercontrol.ascx.vb

<ParseChildren(True), PersistChildren(False), Themeable(False)>
Public Class CommandPanel
    Inherits System.Web.UI.UserControl

    Private mClientScript as string
    <Themeable(False), DefaultValue("")> _
    Public Property ClientScript As String
        Get
            Return mClientScript
        End Get
        Set(ByVal value As String)
            mClientScript = value
        End Set
    End Property
End Class

Page.aspx

<%@ Register src="UserControls/CommandPanel.ascx" tagname="CommandPanel" tagprefix="uc1" %>
......
<uc1:CommandPanel ID="CommandPanel1" runat="server" ClientScript="document.getElementsByName('<%= ReportViewer1.ClientId %>$ctl01$ctl07$ctl00$ctl00$ctl00')[0].click(); return false;" />
......

Note: i know that im saving to a local variable and that it will be cleared on reload and so on but thats not the problem here...


回答1:


<%= expressions cannot be used in server-side controls. You can use <%# syntax (then you must call DataBind on user control) or Attributes property.



来源:https://stackoverflow.com/questions/5802901/asp-net-usercontrol-property-value-does-not-run-markup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!