enablepagemethods in ajaxcontroltoolkit - asp.net

Hi I'm using in my application with ASP.NET WebForms and VB.NET (code behind) the ajaxcontroltoolkit so, i need use enable a page method but if I add
< asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" EnablePageMethods="True" > < /asp:ScriptManager >
to the code this mark error:
You can only add one instance of ScriptManager to the page.
My question is in ajaxcontroltoolkit exist a function equal to EnablePageMethods of ScriptManager?

It may likely that you would have definitely added a ScriptManager somewhere else in your .aspx Page or MasterPage or UserControl.
If you have declared a ScriptManager on your Master page, then in your content pages you would use a ScriptManagerProxy. This will act as a proxy to the real ScriptManager on your master page.
Here is the MSDN link that describes about 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.
Ensure that you have only one asp:Scriptmanager on the
masterpage.
If you don't need a asp:Scriptmanager in materpage then remove it and declare it in content pages whichever needs it.
If you have a ScriptManager in masterpage then make sure you also have only one
asp:ScriptManagerProxy on every content page that might require a script manager.

Related

Multiple instances of a ScriptManager

I have a master page and hundreds of content pages. Every content page contains ToolKitScript Manager for every UpdatePanels on each content page. Right now, I want to add Script Manager on the master page and when I try to execute, error shows "Only one instance of a ScriptManager can be added to the page." So I comment/remove every ToolKitScript line on each content page. What I want to ask, is there any solution so I don't have to comment/remove every single line of code on my hundreds of content page?
Here is the following code on every single content pages which I have to remove one by one.
<AjaxControl:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></AjaxControl:ToolkitScriptManager>
Here is the following code on my master page which I have to add.
<asp:ScriptManager ID="scriptManagerNotif" runat="server" >
<Scripts>
<asp:ScriptReference Path="~/js/jquery-1.2.6.js" />
</Scripts>
</asp:ScriptManager>
You could only have one ScriptManager and ToolkitScriptManager comes with Ajax tool kit, which is a later version of ScriptManager. therefore if you use ToolkitScriptManager instead of the ScriptManager in your Master page it should work fine. You don't need ToolkitScriptManager in each content page then.

How to use AJAX in master page when content pages have ScriptManager?

In my ASP.NET 3.5 project, most content pages have ScriptManager control but the Master Page does not have. I now want to use UpdatePanel in the master page but it is not permitting to put another ScriptManager.
I cannot change to ScriptManagerProxy in content pages as the change needs to be replicated to around fifty pages.
Is there any way to use UpdatePanel in Master Page by either sharing content page's ScriptManager or something else?
three ways I can think.
First way is to use place the ScriptManager inside the ContentPlaceHolder, on the other pages that also have ScriptManager this will be overwrite, in the one that you want to exist, just not use this ContentPlaceHolder, if this is possible.
<asp:ContentPlaceHolder ID="PlaceHolderID" runat="server" >
<asp:ScriptManager ID="ScrMang" runat="server" >
</asp:ScriptManager>
</asp:ContentPlaceHolder>
Second way is to make a second master page, come from the first, and use this second master page with ScriptManager and all the rest, if this is possible.
And last, change all 50 pages, move the ScriptManager to master page, remove it from the rest. Some time we do that :)

ASP.net content tags, and the id attribute

I've made a few master pages in visual studio, and then a few implementing pages, and Visual Studio sticks ID attributes onto all of my tags:
<asp:Content ID="Content1" ContentPlaceHolderID="OtherContent" ></asp:Content>
What gives with the IDs? What are they good for? How do I access them from the code behind?
All controls that run on the server must have an ID attribute as a unique identifier. They are good for finding child controls and keeping the control hierarchy in place. If you have a TextBox that sits in a Panel that sits in an UpdatePanel that's in a WebUserControl that's in a ContentPlaceHolder that's in a Page, then all it takes is one of them not to have a proper ID attribute in order keep the connection between TextBox and Page.
In order to access it from the code behind you need to have the runat="server" attribute set on this tag.

what is the masterpage on this asp.net webformpage?

I have a asp.net webformpage without a MasterPageFile property at the top but I have asp:content tags in there. I assume this page has a masterpage what is the masterpage in this case?
Check web.config maybe there is a global master page define in the <page> element there.
Also, check the code-behind. Maybe it's declared in code.

ASP.NET #Register vs. #Reference

I'm working with referencing user controls on my ASPX page and I'm wondering what the difference is between these two page directives.
#Reference
#Register
#Register is primarily used for registering tag prefixes to declaratively use controls within a page.
<%# Register tagprefix="my" namespace="MyNamespace" %>
<my:CustomControl runat=server />
#Reference is primarily used to refer to a page or user control (by file name or virtual path) to programatically refer to members of the page or control.
<%# Reference Control="MyControl.ascx" %>
<% MyControl ctrl = (MyControl) Page.LoadControl("MyControl.ascx");
ctrl.CustomProperty = "..."; //REFERENCE directive is needed to access property
%>
#Register is the more commonly used directive. You use this when you want to use a user control in your aspx or ascx page declaratively. #Register associates the control with a specific prefix and you can then use it in your markup.
#Reference only tells ASP.NET to compile the other control when your aspx or ascx page is compiled. That makes sure it is available at run-time and can be added to your control hierarchy programmatically. This is less common since dynamically changing user controls at runtime is not comon.
Here's a good blog post about it.
http://weblogs.asp.net/johnkatsiotis/archive/2008/08/13/the-reference-directive.aspx

Resources