I have been dealing with an unusual set of errors when I try to compile my asp.net page. This page is inheriting from my masterpage. It should be getting the Scriptmanager from there. But the errors I am getting suggest that it is not.
Now I have this in my page:
<%# Page Title="MassUpdate" Language="C#"
MasterPageFile="~/Site1.Master"
AutoEventWireup="true"
CodeBehind="Update.aspx.cs"
Inherits="AdminSite.Update"
MaintainScrollPositionOnPostback="true" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" >
<div id="contentarea">
<div>
<h3 style="color:Red; padding-left:5px;">
WARNING - This page can push large amounts of data into the database. Use care when using it!
</h3>
</div>
<asp:ScriptManagerProxy runat="server" >
</asp:ScriptManagerProxy>
And in my masterpage, I have this:
<body>
<header>
<div id="banner">
<h1 style="color:#DBFFFF">UAC Parts Admin</h1>
</div>
</header>
<form id="form1" runat="server">
<div id="container">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
<asp:LoginView ID="LoginView1" runat="server" EnableViewState="false">
<LoggedInTemplate>
<div id="menubar">
<h6>Reports</h6>
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery.js" />
<asp:ScriptReference Path="~/Scripts/jqueryui.js" />
<asp:ScriptReference Path="~/Scripts/menubar.js" />
</Scripts>
</asp:ScriptManager>
The first error is this:
The control with ID '' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.
It happens when I don't have ScriptManager on my page and use ScriptManagerProxy instead.Even though I have ScriptManager on my Master page.
Now when I put a ScriptManager on my page I get a different error.
Only one instance of a ScriptManager can be added to the page.
What do I need to do to get this to work?
Is this an issue with one of my Nuget Packages? (JuiceUI,Widgmo, etc)
I would be glad to post code if requested.
EDIT:
Yeah, this whole thing has been weird. Oddly the master page did not have issues itself. But only when the other pages used it did I have any problems. Moving it to the first element after the form tag was the solution I believe. Though I had also moved the ScriptManagerProxy up a bit in my code too.
The ScriptManager must appear before any ContentPlaceHolders. Generally as Joshua pointed out, the script manager is put at the first element after the form tag. Like so:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery.js" />
<asp:ScriptReference Path="~/Scripts/jqueryui.js" />
<asp:ScriptReference Path="~/Scripts/menubar.js" />
</Scripts>
</asp:ScriptManager>
<div id="container">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
The reason for this is because the .aspx pages that uses this master page provide content that is placed into the ContentPlaceHolder controls. Because your ContentPlaceHolder appeared before your ScriptManager, the ScriptManagerProxy located in your content page was throwing because the ScriptManager would not be defined until later down the page.
This can be a bit odd to think about because you are defining controls in multiple different places. But the codebehind does not execute until everything is put together.
Put the ScriptManager on masterpage and ScriptManagerProxy on the .aspx page.
you need to put the script manager near your form declaration in Master page;
have a look on this Also: Walkthrough: Creating an Ajax-Enabled Web Site
<body>
<form runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
...
</form>
</body>
For Your Second Question:ScriptManager Control Overview
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.
you either have to remove your script manager from master page if wanted to use in Content page or Use proxy in content page with in-addition of script manager in master page
Related
I have below scenario in my ASP.net using C# application
Master page:
I have included below code in Site.Master to register the scriptmanager as used some Telerik controls in it:
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true">
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery-1.8.2.min.js" />
<asp:ScriptReference Path="~/Scripts/knockout-2.1.0.js" />
<asp:ScriptReference Path="~/Scripts/app.js?v=1" />
</Scripts>
</telerik:RadScriptManager>
I have a Data.aspx page on which I have a button which opens up a popup which is ShowPopup.aspx
In ShowPopup.aspx I have used Telerik RadGrid and also a UpdatePanel so included below scriptmanager code:
<asp:ScriptManager ID='scriptManager' runat='server' EnablePageMethods="true" />
I haven't included any scriptmanager code on Data.aspx page.
I have another ascx page which is used to set header of every panel. Below is the code we have used for Header.ascx page:
<asp:UpdatePanel ID="ContentHeaderUpdatePanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<div class="contentHeader">
<div runat="server" id="PageHeader">Content Title</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
And I haven't included any ScriptManager in this ascx file
We have using this header page in ShhowPopup.aspx page like:
<uc:ContentHeader ID="Header" runat="server" Title="Employee Details" />
Issue is, when I click on button in Data.aspx page, a popup (ShowPopup.aspx) page should open giving details, but instead it is giving Server Error in application like:
The control with ID 'ContentHeaderUpdatePanel' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it
proper error description can be found
I tried to add ScriptManager control in Header.ascx page but then it gives Error like:
Only one instance of scriptmanager can be added to the page
I can also see error when I try to see design view of ShowPopup.aspx page:
Error Creating Control - EmployeeGrid Failed to create designer 'Telerik.Web.UI.RadGrid, Telerik.Web.UI, Version=2013.1.417.45, Culture=neutral, PublicKeyToken=121fae78165ba3d4'
One more issue is there.
I have IIS setup at my laptop and also deployed code on server. Error can not be reproduced on the one where IIS is setup. Why is it so?
I've applied Master page to my existing application.Master Page has form control who runs at server . My page have multiple forms in which some forms runs at server and some doesn't runs at server . How can I Handle this Situation :
Master Page :
<form id="form1" runat="server">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
Content Page :
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<form action="VersionControl_11g.aspx" name="Form1" id="Form1" >
...
</form>
<form runat="server" enctype="multipart/form-data" method="post" >
...
</form>
<form action="VersionControl_11g.aspx" name="Form2" id="Form2">
...
</form>
<form runat=server >
...
</form>
</asp:Content>
I have tried closing the form tag in the begining of Content page then again opened the form tag where required in the content page but more than one form with runat=server attribute are not allowed .
I want the way where I could use simple Forms without runat server attribute nested inside the Form exists in Master page .
As due the huge functionality of the page , I can not modify the overall structure of page.
Please Help me :(
Thanks
VERY very basic question. I'm trying to learn ASP.NET. I created a default website1 in VS 2013 Community I get a ton of files. When I run the app in IS, the default.aspx web page appears and all is OK, but above the web page is a banner with links to contact.aspx, login.aspx. register.aspx, etc. and I cannot find where that banner is? It's not on default.aspx. Where is it? Seaching the project for "Contact.aspx" only returns one result, the page itself, as an example.
It's probably coming from a Master Page. Look at the <%# Page %> header at the tops of the .aspx files. You'll see they reference a master page. A Master Page is used to provide structure to the site. It means you don't have to write the same HTML for common elements on every single content page. Content pages (.aspx) then can have their content inserted into the Master Page. And yes, you can nest master pages. This is all done through the <asp:ContentPlaceHolder /> (higher level Master Page) and <asp:Content /> (nested Master Page or Content Page) tags.
Let's look at an example:
MasterPage.master
<%# Master Language="C#" %>
<!DOCTYPE html>
<html>
<head runat="server" >
<title>Master page title</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="Main" runat="server" />
</div>
<div>
<asp:ContentPlaceHolder id="Footer" runat="server" />
</div>
</form>
</body>
</html>
Default.aspx
<%# Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
Main content here.
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Footer" runat="Server" >
Footer content here.
</asp:Content>
The resulting HTML will look like this on the client when you access Default.aspx:
<!DOCTYPE html>
<html>
<head>
<title>Content Page 1</title>
</head>
<body>
<form id="ContentPage_form1">
<div>
Main content here.
</div>
<div>
Footer content here.
</div>
</form>
</body>
</html>
Take special note of how the ID of the form changed from the server side to the client. This trips a lot of people up when they start doing client side JavaScript. If you want the ID to not change, you have to add the ClientIDMode="Static" attribute to the control (you can also set it at page, web.config, or machine.config levels).
I'm trying to use CKEditor in my Webforms application and I have tried many other methods without success. Can someone help? The site uses a Site.Master file which all the aspx files provide content for using content place-holders. So I place the JavaScript call in the ASPX rather than in the master file.
I'm also trying to get it to edit in a content editable div element. It works fine in a small test site but not in my application. Any ideas?
My Site.master has two content placeholders I want to use:
<asp:ContentPlaceHolder ID="Scripts" runat="server" />
and
<asp:ContentPlaceHolder ID="MainContent" runat="server">
An then my aspx files have:
<asp:Content ID="Content3" ContentPlaceHolderID="Scripts" runat="server">
<script src="ckeditor/ckeditor.js"></script>
</asp:Content>`
and
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="renderTarget" renderwidth="1100">
</asp:Content>
</asp:Content>
Somewhere in my JavaScript, I set the content editable of my renderTarget div to true.
$(".contentbox[dynamic='true']").attr("contenteditable", "true");
And at this point, I expect CKedtor to add its controls to the div. But It doesn't. i use the same process with TinyMCE and it works fine.
If you have CKEditor in your project correctly, it is as simple as:
<textarea cols="80" class="ckeditor" id="editor1" name="editor1" rows="10"></textarea>
or even
<div contenteditable="true">...</div>
Also, you may want to read up on jQuery Selectors.
An example more like what you posted:
<div id="ckMe">...</div>
<script>
$(document).ready(function () {
$("#ckMe").attr("contenteditable", "true");
});
</script>
all you need is to install the version for asp.net in your project and then just use it as simple as adding a usercontrol:
<ckeditor:ckeditorcontrol ID="CkEditor1" runat="server"></ckeditor:ckeditorcontrol>
Documentation from ckEditor
<%# Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" ClientIDMode="AutoID" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="server">
<%
foreach (var item in AllSales)
{
//Here i have just set a breakpoint to see if it loops the AllSales list when I press the update button
}
%>
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<p>Update Panel: DateTime.Now: <%= DateTime.Now.ToString() %></p>
<asp:Button runat="server" ID="Submit" Text="Update" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
The script manager code is in the masterpage :
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
Problem here is that everytime i click the Update button it loads the page again and loops the "AllSales" list , i want to only update a section and not have to do unnecessary loops.
Here is the fun part : If i remove the masterpage, it works ! But with the masterpage, it dont , why?!
You need to use a server control to initiate the update rather than a normal html input button. Try using:
<asp:Button ID="ActivitySubmit" Text="Submit" runat="server" />
The reason for such behavior is that you use plain html submit button instead of ASP.NET server button. Thus page submitted to server without involving ASP.NET Ajax functionality. Replace ActivitySubmit button with asp:Button control
Set the UpdateMode mode property to Conditional. The default value for UpdateMode is Always, If the UpdateMode property is set to Always, the UpdatePanel control's content is updated on every postback that originates from anywhere on the page, reference
Edit: You are using input type="submit" which probably causing the post back replace it with asp:Button to get the ajax call to work.
I have tested the same code with only change in the button type, and it refreshes only the update panel content. The problem is your site is targeting .NET 3.0 but you need to target at least to 3.5. I have tested on 3.0, it does not work but on 3.5 and 4.0, it works fine. So the easier and safer solution is to target 3.5 onwards. But If you want to use .NET 3.0, I will try to find a workaround. Please let me know.
I tried to recreate your problem but it is working fine in my case. Try creating a new .aspx file and paste the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Outside UpdatePanel</p>
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<p>DateTime.Now: <%= DateTime.Now.ToString() %></p>
<asp:Button runat="server" ID="SubmitButton" Text="Go" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
This was tested in VS2010 using .NET 4.0 in an Empty Web Application. Does this work for you as well? I tried the same example using a Master page with a content placeholder. This yields the same (properly working) results. From this I gather there is something else going on on your page that we're missing. Is there?
[Edit]
I made another simple example, this time with a Master page and a Content page.
Master page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
<p>Master Page: DateTime.Now: <%= DateTime.Now.ToString() %></p>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Aspx page:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<p>Update Panel: DateTime.Now: <%= DateTime.Now.ToString() %></p>
<asp:Button runat="server" ID="Submit" Text="Update" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Again this works without a problem in the same environment as the other example. It looks like you'll have to tell me about the .NET framework you're targeting and what else you've got set up in your master page and aspx page, because:
In .Net 3.5 and up this will work. In lower versions however, it won't. I'm afraid I've been unable to figure out how to fix it in lower versions though. :(
In your Page tag just add
ClientIDMode="AutoID"
I think you can try and put the form inside the updatepanel, or you can try and change children as triggers property of the updatepanel like this :
<asp:UpdatePanel runat="server" ID="UpdatePanel1" ChildrenAsTriggers="False">
and then add the button as trigger like this
ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(SubmitButton);
try addind this part to your UpdatePanel:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Submit" />
</Triggers>