gpt4 book ai didi

c# - 在 asp.net 中只能将一个 ScriptManager 实例添加到页面

转载 作者:太空狗 更新时间:2023-10-29 22:04:27 25 4
gpt4 key购买 nike

当我尝试添加用户控件时出现此错误

Only one instance of a ScriptManager can be added to the page

代码:

.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisaUserControl.ascx.cs" Inherits="Portal.VisaUserControl" %>
<%@ Register Assembly="BasicFrame.WebControls.BasicDatePicker" Namespace="BasicFrame.WebControls" TagPrefix="dp" %>
<asp:ScriptManager ID="scriptmanager1" runat="server"></asp:ScriptManager>
<div id="divreg" runat="server">
<table id="tbl" runat="server">
<tr>
<td>
<asp:Label ID="lbl2" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td> Visa Number:</td>
<td><asp:TextBox ID="txtUser" Width="160px" runat="server"/></td>
<td> Country Name:</td>
<td><asp:DropDownList ID="dropCountry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td> Type of Visa:</td>
<td><asp:DropDownList ID="dropVisa" Width="165px" runat="server" OnSelectedIndexChanged="dropVisa_SelectedIndexChanged"></asp:DropDownList></td>
<td> Type of Entry:</td>
<td><asp:DropDownList ID="dropEntry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td> Expiry Date</td>
<td><asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="txtDate" PopupButtonID="Imgbtnfromdate" Format="dd/MM/yyyy">
</ajaxToolkit:CalendarExtender>
</td>
<td>
<asp:Button ID="btnRemove" Text="Remove" runat="server" OnClick="btnRemove_Click" />
</td>
</tr>
</table>
</div>

.aspx.cs

  protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);

GenerateControls();
}



private void GenerateControls()
{
foreach (string i in NoOfControls)
{
VisaUserControl ctrl = (VisaUserControl)Page.LoadControl("VisaUserControl.ascx");
ctrl.ID = i;
this.rpt1.Controls.Add(ctrl);
}
}

问题来了

    protected void btnAddVisa_Click(object sender, EventArgs e)
{

List<string> temp = null;
var uc = (VisaUserControl)this.LoadControl(@"VisaUserControl.ascx");

string id = Guid.NewGuid().ToString();
uc.ID = id;

temp = NoOfControls;
temp.Add(id);
NoOfControls = temp;
rpt1.Controls.Add(uc);
}

在下图中,如果我单击“添加”按钮,则会出现错误:

enter image description here

最佳答案

尝试删除 ScriptManager从用户控制。

您肯定在 .aspx 的其他地方添加了 ScriptManager页或母版页。检查这些页面。

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

如果您需要 ScriptManager在母版页上,在这种情况下,用户控件中不需要有 ScriptManager。遵循以下规则:

  • 确保您只有一个 <asp:Scriptmanager>在母版页上。
  • 确保你也有一个且只有一个<asp:ScriptManagerProxy>在可能需要脚本管理器的每个内容页面上

下面是 MSDN ScriptManager控制。

Only one instance of the ScriptManager control can be added to the page. The page can include the control directly, or indirectly inside a nested component such as a user control, content page for a master page, or nested master page. If a page already contains a ScriptManager control, but a nested or parent component needs additional features of the ScriptManager control, the component can include a ScriptManagerProxy control. For example, the ScriptManagerProxy control enables you to add scripts and services that are specific to nested components

关于c# - 在 asp.net 中只能将一个 ScriptManager 实例添加到页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19087044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com