How To Add ToolkitScriptManager On MasterPage To Use Ajax Controls On Content Pages In Asp.Net. When we use AjaxControlToolkit on content pages of site with master page, we get some errors becuase ScriptManager not placed properly.
One of such error is
This error occurs if you are using .NET framework 3.5 or avobe and have placed ScriptManager.
To fix this error remove ScriptManager and place ToolkitScriptManager on Master Page.
If you receive
Then either you have placed ToolkitScriptManager in head section of MasterPage or in ContentPlaceHolder.
ToolkitScriptManager must be placed within the form tag of MasterPage.
If you place ToolkitScriptManager on master page as mentioned above, YOu don't need to put any scriptmanagerproxy or ToolkitScriptManager on content pages.
HTML SOURCE SHOULD LOOK LIKE SHOWN BELOW
HTML SOURCE OF CONTENT PAGES WITH AJAX MENTIONED BELOW
Hope this helps
One of such error is
"Toolkit requires ASP.NET Ajax 4.0 scripts. Ensure the correct version of the scripts are referenced. If you are using an ASP.NET ScriptManager, switch to the ToolkitScriptManager in AjaxControlToolkit.dll."
This error occurs if you are using .NET framework 3.5 or avobe and have placed ScriptManager.
To fix this error remove ScriptManager and place ToolkitScriptManager on Master Page.
If you receive
"'ToolkitScriptManager' must be placed inside a form tag with runat=server" error
Or
The control with ID 'yourAjaxcontrolID' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it error.
Or
The control with ID 'yourAjaxcontrolID' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it error.
Then either you have placed ToolkitScriptManager in head section of MasterPage or in ContentPlaceHolder.
ToolkitScriptManager must be placed within the form tag of MasterPage.
If you place ToolkitScriptManager on master page as mentioned above, YOu don't need to put any scriptmanagerproxy or ToolkitScriptManager on content pages.
HTML SOURCE SHOULD LOOK LIKE SHOWN BELOW
1: <%@ Master Language="C#" AutoEventWireup="true"
2: CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
3:
4: <%@ Register assembly="AjaxControlToolkit"
5: namespace="AjaxControlToolkit" tagprefix="asp" %>
6:
7: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
8: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
9:
10: <html xmlns="http://www.w3.org/1999/xhtml">
11: <head runat="server">
12: <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
13: <title>Using AjaxControlToolkit With MasterPage</title>
14: <asp:ContentPlaceHolder id="head" runat="server"/>
15: </head>
16:
17: <body>
18: <form id="form1" runat="server">
19: <div>
20: <asp:ToolkitScriptManager ID="ToolkitScriptManager1"
21: runat="server">
22: </asp:ToolkitScriptManager>
23:
24: <asp:ContentPlaceHolder id="ContentPlaceHolder1"
25: runat="server">
26: </asp:ContentPlaceHolder>
27: </div>
28: <p style="text-align: center">master page</p>
29: Place your master page contents here
30: </form>
31: </body>
32: </html>
HTML SOURCE OF CONTENT PAGES WITH AJAX MENTIONED BELOW
1: <%@ Page Title="" Language="C#"
2: MasterPageFile="~/MasterPage.master"
3: AutoEventWireup="true" CodeFile="Default2.aspx.cs"
4: Inherits="Default2" %>
5:
6: <%@ Register Assembly="AjaxControlToolkit"
7: Namespace="AjaxControlToolkit" TagPrefix="asp" %>
8:
9: <asp:Content ID="Content1" ContentPlaceHolderID="head"
10: Runat="Server">
11: </asp:Content>
12:
13: <asp:Content ID="Content2"
14: ContentPlaceHolderID="ContentPlaceHolder1"
15: Runat="Server">
16:
17: <asp:TextBox ID="TextBox1" runat="server"/>
18: <asp:PasswordStrength ID="PasswordStrength1"
19: runat="server"
20: TargetControlID="TextBox1"
21: DisplayPosition="RightSide"
22: StrengthIndicatorType="BarIndicator"
23: BarBorderCssClass="BarBorder"
24: StrengthStyles="BarIndicatorweak;
25: BarIndicatoraverage;BarIndicatorgood;">
26: </asp:PasswordStrength>
27:
28: </asp:Content>
Hope this helps
If you like this post than join us or share
1 comments:
Thank you sir! I was chasing down AjaxControlToolkit release versions as the culprit. I did not realize that the content page also needed the <%@ Register Assembly="AjaxControlToolkit" directive in place. I would have thought that to cause a conflict but it doesn't :)
Post a Comment