简体   繁体   中英

asp.net inline tags inside user control

I'm trying to create something almost similar to this [1]: http://weblogs.asp.net/infinitiesloop/archive/2007/09/17/inline-script-inside-an-asp-net-ajax-updatepanel.aspx

The problem I ran into is that if I use an inline tag, the page property ClientID it's resolved as "__Page" although this doesn't happen with child controls of that page. So for example if I use the control like this

  <tag:InlineScript runat="server">
        <script type="text/javascript">
          alert('<%= ClientID %>');
          alert('<%= SomeLabelInTheSamePage.ClientID %>');
        </script>
  </tag:InlineScript>

the page is rendered as:

    <script type="text/javascript">
      alert('__Page');
      alert('MainContent_CorrectLabelId');
    </script>

Any idea why?

[1] the diference is that I'm using a user control (instead of server control) decorated with ParseChildren(false), same code as the page I linked.

Try this:

<tag:InlineScript id="myInlineScript" runat="server">
    <script type="text/javascript">
        alert('<%=myInlineScript.ClientID %>');
        alert('<%=SomeLabelInTheSamePage.ClientID %>');
    </script>
</tag:InlineScript>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM