Asp.net 脚本管理器与按钮冲突

发布于 2024-09-06 00:49:19 字数 766 浏览 5 评论 0原文

我正在开发一个 asp.net 应用程序,并且有一些在 OnInit 事件上动态创建的控件。

其中一个控件是一个 asp 按钮,到目前为止一直运行良好。当我将 ScriptManager 添加到我的页面时,同一按钮无法回发。仅当取出 ScriptManager 时它才起作用。

类似的事情曾经发生在其他人身上吗?我是否以某种方式使页面无效?

编辑:

这是我的脚本管理器标签:

    <asp:ScriptManager ID="ScriptManager1" runat="server" 
EnablePageMethods="true" EnableScriptGlobalization="true" 
EnableScriptLocalization="true"> 
</asp:ScriptManager>

//My Dynamic Button:
Button button1 = new Button
            {
                ID = "button1",
                Text = "Ok"
            };
            button1.Click += new EventHandler(Button1_Click);

好的,一件奇怪的事情。 还没有弄清楚我出现这种行为的原因,但是,如果按钮位于容器内(例如表格单元格),那么它就可以回发。可能是一个解决方法

I'm working on an asp.net app and I have some controls that are created dynamically on the OnInit event.

One of that controls is an asp button that has been working fine until now. When I add a ScriptManager to my page, that same button is unable to postback. It's only working if a take the ScriptManager out.

Has anything like this ever appened to somebody else? Am I invalidating the page somehow?

Edit:

This is my script manager tag:

    <asp:ScriptManager ID="ScriptManager1" runat="server" 
EnablePageMethods="true" EnableScriptGlobalization="true" 
EnableScriptLocalization="true"> 
</asp:ScriptManager>

//My Dynamic Button:
Button button1 = new Button
            {
                ID = "button1",
                Text = "Ok"
            };
            button1.Click += new EventHandler(Button1_Click);

Ok, one weird thing.
Havent figured it out the reason I'm having this behaviour, but, if the button is inside a container, say, a table cell, then it's able to post back. Might be a workaround

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽梦忆笙歌 2024-09-13 00:49:19
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" />
    <div>      
      <p id="lblClickedFlag" runat="server">
      </p>
      <div id="container" runat="server">
      </div>
    </div>
</form>


protected void Page_Init(object sender, EventArgs e)
{
    //My Dynamic Button:
    Button button1 = new Button
    {
        ID = "button1",
        Text = "Ok"
    };
    button1.Click += Button1_Click;
    container.Controls.Add(button1);
}

protected void Button1_Click(object sender, EventArgs e)
{
    lblClickedFlag.InnerText = "clicked";
}


this works for me
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" />
    <div>      
      <p id="lblClickedFlag" runat="server">
      </p>
      <div id="container" runat="server">
      </div>
    </div>
</form>


protected void Page_Init(object sender, EventArgs e)
{
    //My Dynamic Button:
    Button button1 = new Button
    {
        ID = "button1",
        Text = "Ok"
    };
    button1.Click += Button1_Click;
    container.Controls.Add(button1);
}

protected void Button1_Click(object sender, EventArgs e)
{
    lblClickedFlag.InnerText = "clicked";
}


this works for me
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文