脚本管理器问题 [英] Script Manager issue

查看:71
本文介绍了脚本管理器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi I am using below code to conditionally add sriptmanager tag ,but below code is always adding scriptmanager tag irrespective of condition.
Please check the flaw in this code and suggest how can I add ScriptManager

    <form id="Form1" method="post" runat="server" class=top_form>
    <asp:placeholder id="ViewPlaceholder" runat="server"></asp:placeholder>
               <%
    if (Request.QueryString["UseAjax"] == "true")
    {
                   bool AppValue= Convert.ToBoolean(ConfigurationManager.AppSettings.Get("AddScriptManager"));
                  if (AppValue){
    %>
            <asp:ScriptManager ID="smanager1" runat="server" ScriptMode="Release" />

    <%}
    }%>
    </form>

Thanks,
Salmon

推荐答案

解决方法是:

1.仅将PlaceHolder 控件保留在aspx中:

Here is the solution:

1. Keep only the PlaceHolder control in the aspx:

<asp:placeholder id="ViewPlaceholder" runat="server"></asp:placeholder>



2.将条件代码放在CodeBehind中:



2. Put the conditional code in the CodeBehind:

protected void Page_Init(object sender, EventArgs e)
{
        if (Request.QueryString["UseAjax"] == "true")
        {
            bool AppValue = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("AddScriptManager"));
            if (AppValue)
            {
                ScriptManager script = new ScriptManager();
                script.ID = "smanager1";
                script.ScriptMode = ScriptMode.Release;
                ViewPlaceholder.Controls.Add(script);
            }
        }
}



不幸的是,如果您将条件代码放入标记中,则如果您要包含ScriptManager的话,它将无法按预期工作.在这种要求下,您必须如上所述在CodeBehind中添加ScriptManager .



Unfortunately, if you put the conditional code in the Markup, it will not work as expected in case if you want to include a ScriptManager. In such requirement, you have to add the ScriptManager in the CodeBehind as described above.


这篇关于脚本管理器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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