HTML controls in ASP pages - asp.net

I am new to ASP.NET. When I was writing code in .aspx page I am trying to use HTML tag in it then i got the following error:
Only Content controls are allowed directly in a content page that contains Content controls.
Can any one suggest the solution for it? And how can I use those tags?

if you are using master-page in that page, make sure all your html and server controls wrapped by Content Control.
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
html......
</asp:Content>

Related

Can't add content on pages using webform template in Umbraco

I am using umbraco 7 and i'm not really good on MVC, so i am using webforms and when i try to use a webform template i can't add content on the page, just on the template.
Here i use in de default.master file the contentplace holder like this:
<div id="mainContent">
<asp:ContentPlaceHolder id="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
Then i create the template called "Text Webform" and this is the code:
<%# Master Language="C#" MasterPageFile="~/umbraco/Masterpages/Default.master" AutoEventWireup="true" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
This content is displayed
Am i forgetting some code to add here?
</asp:Content>
Click on this to see screenshot
The problem is when i try to add content in a page that is using "Text Webform" template, that content is not displayed, as you can see on the screenshots here
I'm sure i need to add some content in the Text Webform template but i don't know exactly what and i'm desperate, please somebody provide any help,
Thanks.
You have to define what fields (eg properties from your document type) to show where in your template. I believe this is what you are looking for? https://our.umbraco.org/documentation/Reference/Templating/Masterpages/umbracoitem - just
Ok, now i can explain it better,
I just want the equal function to #CurrentPage.GetGridHtml("content", "fanoe") using a webform template..

Form tag inside master page and content page

I have one master page and several content pages , I need to put a form tag inside a master page to handle sending data from my html elements and do this for my content pages as well .but I need to understand what is the best way to structure for such this scenario and what would be the effect of form tag of master page on content pages ? is it possible to put form tag in content pages when the master page has this tag inside itself ? I appreciate if I have in detail explanation ?
The <form runat="server"> element lives in the master page by default when you add a new one to your project; all child pages are implemented using ContentPlaceHolders.
For example, the master page: -
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
You can have as many ContentPlaceHolders as you need (often only one is needed though). If you then add a "child page using master page", the page-specific content is added inside the relevant <asp:Content> element - these are added by default once you have specified the master page to use when adding a "child page using master page": -
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<!-- your markup, controls etc.. -->
</asp:Content>
Have a read of the MSDN docs for more - http://msdn.microsoft.com/en-us/library/aa581781.aspx

ASP.NET Master Page not updating Child Page

I have made a site that is based off of a MasterPage and after creating a few pages I added a new <asp:ContentPlaceHolder> but it seems the existing pages wont update to include it, however new pages do.
Is there a way to force an update, or is there a proper way to do this? I just saved the Master Page and hoped for the best.
You need to add the new <asp:ContentPlaceHolder> to your old aspx pages manually.
in your master page:
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="new_one" runat="server"></asp:ContentPlaceHolder>
in your old aspx pages, add:
<asp:Content ID="Content3" ContentPlaceHolderID="new_one" runat="server">
</asp:Content>
If you create a new content placeholder in your master page, your content pages don't NEED to have a corresponding <asp:Content>. They only need one if you want to replace the default content placed in the master page.
And if you're going to update each page with its own content, then adding the <asp:Content> tags is likely a relatively small inconvenience.
Unfortunately there is not a way for Visual Studio to search out all your content pages and update them with new <asp:Content> controls.
However, you could do it fairly quickly by finding using the id of an existing <asp:Content> control, and do a ctrl+shift+F and replace with your new <asp:Content> plus what you searched for.
For example, if your content pages already all had a
<asp:Content ID="Content3" ContentPlaceHolderID="old_one" ... />
then you could search for that and replace with
<asp:Content ID="Content4" ContentPlaceHolderID="new_one" runat="server" /><asp:Content ID="Content3" ContentPlaceHolderID="old_one" ... />
Not exactly pretty, but it could save some time.

How to add master page to already created webform?

I have a asp.net webform application. Now I have to add master page in this application, but I don’t know how to merge or add new created master page with old webforms? How to handle html in webforms like <head> , <body> ? Any link in this regard will be helpful.
1- Define the fixed elements in your design, and put them inside the newly created master page
2- Define the dynamic ones, and add asp:ContentPlaceHolder for them ( most commonly one for HEAD, one for main content in your BODY , and one for side content "if applicable")
<asp:ContentPlaceHolder ID="CphHead" runat="server">
</asp:ContentPlaceHolder>
3- In your pages, add MasterPageFile="~/MASTER_PAGE_PATH" inside the Page directive.
4- Add asp:Content sections inside your pages which will hold the dynamic content in your pages, and don't forget to reference the correct ContentPlaceholder ID.
<asp:Content ID="HeadContent" ContentPlaceHolderID="CphHead" runat="server">
// Your content goes here...
</asp:Content>
5- Copy your page content inside these asp:content sections, and BOOOOM....you are done.
at the top of the new page in the '<%# page #>' tag add 'MasterPageFile="~/Site.Master"'
then add the needed placeholders
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>
of course modify these to the names you are using
you can add the content holder tag in master page. So when you add 'MasterPageFile="~/Site.Master"' then you able to add content of other pages.

a page can have only one server-side form tag

I am using master page and when I run this page, it shows the following error message:
a page can have only one server-side form tag
How can I solve this problem?
I think you did like this:
<asp:Content ID="Content2" ContentPlaceHolderID="MasterContent" runat="server">
<form id="form1" runat="server">
</form>
</asp:Content>
The form tag isn't needed. because you already have the same tag in the master page.
So you just remove that and it should be working.
It sounds like you have a form tag in a Master Page and in the Page that is throwing the error.
You can have only one.
Does your page contain these
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:content>
tags, and are all your controls inside these? You should only have the Form
tags in the MasterPage.
Here are some of my
understanding and suggestion:
Html element can be put in the body of html pages and html page does
support multiple elements, however they can not be nested each
other, you can find the detailed description from the W3C html
specification:
The FORM element
http://www.w3.org/MarkUp/html3/forms.html
And as for ASP.NET web form page, it is based on a single server-side form
element which contains all the controls inside it, so generally we do not
recommend that we put multiple elements. However, this is still
supported in ASP.NET page(master page) and I think the problem in your
master page should be caused by the unsupported nested element, and
multiple in the same level should be ok. e.g:
In addition, if what you want to do through multiple forms is just make our
page posting to multiple pages, I think you can consider using the new
feature for cross-page posting in ASP.NET 2.0. This can help us use button
controls to postback to different pages without having multpile forms on
the page:
Cross-Page Posting in ASP.NET Web Pages
http://msdn2.microsoft.com/en-us/lib...39(VS.80).aspx
http://msdn2.microsoft.com/en-us/lib...40(VS.80).aspx
Use only one server side form tag.
Check your Master page for <form runat="server"> - there should be only one.
Why do you need more than one?
Sometime when you render the current page as shown in below code will generate the same error
StringWriter str_wrt = new StringWriter();
HtmlTextWriter html_wrt = new HtmlTextWriter(str_wrt);
Page.RenderControl(html_wrt);
String HTML = str_wrt.ToString();
so how can we sort it?
please remove " runat="server" " from "form" tag then it will definetly works.

Resources