0

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

Viktor S.
  • 12,736
  • 1
  • 27
  • 52
Peter
  • 37,042
  • 39
  • 142
  • 198

1 Answers1

1

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

Tomas Voracek
  • 5,886
  • 1
  • 25
  • 41
  • What do you mean with can't be used in server-side controls? its not used in the usercontrol its used where the usercontrol in used if you understand what i mean? what makes my usercontrol diffrent from a button that hinders me from using <%=? – Peter Apr 27 '11 at 11:31
  • 1
    Read http://blogs.msdn.com/b/dancre/archive/2007/02/13/the-difference-between-lt-and-lt-in-asp-net.aspx, http://kbalertz.com/976112/Introduction-inline-expressions-Framework.aspx. Can't find relevant MSDN docs. – Tomas Voracek Apr 27 '11 at 11:35
  • Thanks for those links ill read them but the thing i don't get that it works with <%= in the – Peter Apr 27 '11 at 11:45
  • Thanks now i think i get it some what atleast <%= is the same thing as <% Response.Write(... then it does make some what of a sense that i can't use it in my property... but the big question is still why does it work on the button control.... – Peter Apr 27 '11 at 12:01
  • I think it's because their base classes are not same. Button inherits from WebControl, but user controls derive from, well....UserControl class. – Tomas Voracek Apr 27 '11 at 12:15