简体   繁体   English

用户控件内部的asp.net内联标签

[英]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 我正在尝试创建几乎与此[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. 我遇到的问题是,如果我使用内联标签,则页面属性ClientID会解析为“ __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. [1]的不同之处在于,我正在使用装饰有ParseChildren(false)的用户控件(而不是服务器控件),该代码与我链接的页面相同。

Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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