只能将ScriptManager的一个实例添加到asp.net中的页面 [英] Only one instance of a ScriptManager can be added to the page in asp.net
问题描述
当我尝试添加用户控件时,出现此错误
When I'm trying to add user control I got this error
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);
}
在下图中,如果单击添加按钮,则出现此错误
In the below image if Click add button I got this error
有什么想法吗?预先感谢
Any ideas? Thanks in advance
推荐答案
尝试从用户控件中删除 ScriptManager
.
Try removing ScriptManager
from user control.
您肯定在 .aspx
页面或母版页的其他位置添加了ScriptManager.检查这些页面.
You have definitely added a ScriptManager somewhere else in your .aspx
Page or MasterPage. Check these pages.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
如果在主页"页面上需要 ScriptManager
,则在userControl中不需要ScriptManager.请遵循以下规则:
In case you require ScriptManager
on Master page,In this case, there is NO need to have a ScriptManager in userControl. Follow below rules:
- 确保主页上只有一个
< asp:Scriptmanager>
. - 确保在每个可能需要脚本管理器的内容页面上,您也只有一个
< asp:ScriptManagerProxy>
.
下面是 MSDN
关于 ScriptManager
控件.
只能将ScriptManager控件的一个实例添加到页.该页面可以直接或间接包含控件嵌套组件(例如用户控件)中的内容页面母版页或嵌套母版页.如果页面已经包含一个ScriptManager控件,但需要嵌套或父组件ScriptManager控件的其他功能,组件可以包括一个ScriptManagerProxy控件.例如,通过ScriptManagerProxy控件,您可以添加脚本和服务嵌套组件特有的
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
这篇关于只能将ScriptManager的一个实例添加到asp.net中的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!