ASP.NET用户控件属性值未运行<%=标记 [英] ASP.NET Usercontrol Property value does not run <%= markup

查看:40
本文介绍了ASP.NET用户控件属性值未运行<%=标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有一个带有属性"ClientScript"的用户控件,在使用该用户控件的aspx文件中,我将该值设置为 = document.getElementsByName('<%= ReportViewer1.ClientId%> $ ctl01$ ctl07 $ ctl00 $ ctl00 $ ctl00')[0] .click();返回false;

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;

这里的问题是随便将传递给该属性,而不是首先对其进行解析,而是将其替换为ClientID.

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

我在按钮OnClientClick上应用了相同的客户端脚本,并且该脚本起作用了...

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?

这是我的代码:

Usercontrol.ascx.vb

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

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...

推荐答案

<%=表达式不能在服务器端控件中使用.您可以使用<%#语法(然后必须在用户控件上调用DataBind)或属性属性.

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

这篇关于ASP.NET用户控件属性值未运行&lt;%=标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆