Help in solution more than one form in asp.net as to my logic its compulsory - asp.net

As per my layout one form(all forms with runat=server) should be in header right top and
the other one I want to place in section's article. So I will have no problem in positioning of contents. How do I solve it?
My design: Login & logout are contained in form at header top-right;
article:Embedding AJAX4 accordian & tab container
but this requires it to be placed in form as <asp:scriptManager should be in form having runat=server.
(article has aside_left & aside_right near to it seperated and header at top seperated which contains the form)
So any Solution for this?
Do I have to change the logic?
I am working with visual studio 2010 asp.net 4 IIS v6 of windows7 x86

If I understand your problem correctly, you can do what you are looking for with Master pages: http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx
Create a master page with a content section for the header and another for the rest of the page. The create pages for both of those content sections.

This sounds like you need a MasterPage containing your login and logout buttons, and then a content page containing your 'article'.
Master page (.master)
<form id="form1" runat="server">
<!-- login / logout controls here -->
<asp:ContentPlaceHolder ID="Article" runat="server">
</asp:ContentPlaceHolder>
</form>
Content page (.aspx):
<asp:Content ID="ArticleContent" ContentPlaceHolderID="Article" runat="server">
<!-- Accordion and things here -->
</asp:Content>
If that's not what you're after, then this link provides details on how to implement multiple forms on a page in ASP.NET.

Related

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

MaterPage re-design in asp.net. how to create diff layouts for header and footer

I am being told to re-design MasterPage. My company uses AbleCommerce system and let me tell you its very tricky. I have a different layouts templates created in HTML by AbleCommerece long time ago and now i need to re-design my masterpage.
ex:
OneColumn.html
<div id="wrapper">
[[layout:header]]
<div id="Content">
<div id="MainContent">
[[layout:content]]
</div>
</div>
[[layout:footer]]
</div>
RightSidebar.html
[[layout:header]]
<div id="outerContentWrapper">
<div id="innerContentWrapper">
[[layout:content]]
[[layout:rightsidebar]]
</div>
</div>
<div id="footerbar">[[layout:footer]]</div>
MasterPage:
only one ContentPlaceHolder in MasterPage
<asp:ContentPlaceHolder ID="PageContent" runat="server">
</asp:ContentPlaceHolder>
ContentPage
<cb:ScriptletPart ID="ShowProduct" runat="server" Layout="One Column" Header="Standard Header" Content="Show Product Page" Footer="Standard Footer" Title="Show Product" AllowClose="False" AllowMinimize="false" />
Now, Content Page looks for One Coulmn.html and loads the html then One Column Loads the Standered Header.html page which reference header webuser control and layout loads Show Product Page.html page which reference another set of webuser controls and so on..
Issue: by following this design we now have over 100 html files which references Asp.Net UserControls. So whenever we want to create new page on our website, we have to create .aspx and then include **<cb:ScriptletPart>**, create new set of HTML files and then USerControls.
I want to get rid of this system and Load userControls directly inside the .aspx page, that's easy BUT then i dont know how can i inform masterpage to use One Column Layout OR anyother Layout.
Is there way to tell masterpage from content page to use the layout sepcified by public property in content page. OR anyother suggestion to deal this kind of situation.
To access controls within the master page, there are two approaches:
By means of public properties and methods
If you observed, the content page doesn’t have the header and title tags.
So if we want to modify the title of the content page –and this is obligatory- we need to access the title tag.
Primarily we need to change the title tag so it is accessible from the code page.
Simple, we need to add id and runat attributes as follows:
<title id="sometitle" runat="server"></title>
Then, in the master page, add this property:
public string SomeTitle
{
set
{
sometitle.Text = value;
}
}
And finally within the content page, we add this snippet on the Load event.
MasterPage masterPage = MasterPage)this.Master;
masterPage.mainTitle = "Hello World";
Please Note:
Because the Master property returns a reference of type MasterPage, we need to cast it to MasterPage type. We can avoid this by adding the #MasterType directive in the content page as follows:
<%# MasterType TypeName=" MasterPage " %>
MasterPage myMaster =this.Master;
I hope that helps.

HTML controls in ASP pages

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>

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.

ASP.NET page content - where does this belong?

I am working on a web application that has a single master page and several content pages. Each page will have a small sidebar to the right of the main content with some brief content. However, that brief content is specific to the page you are on. I can't decide whether to put that on each individual page, or in the master page in a MultiView with some logic in code-behind to specify which view is shown based on which page you are on.
Which seems more elegant? I'm still fairly new with ASP.NET and I'm trying to get a good feel for proper architecture, etc.
You can create multiple content placeholders in a single masterpage. So in your case I would create two. One for the article's content and one for the sidebar like:
<!-- some html-->
<asp:contentplaceholder id="ArticleContents" runat="server">
</asp:contentplaceholder>
<!-- some more html-->
<asp:contentplaceholder id="ArticleSidebar" runat="server">
</asp:contentplaceholder>
<!-- even more html-->
then you could have the article contents and the sidebar contents both in the same page and place it in the correct spot using something like
<asp:Content ID="article" ContentPlaceHolderID="ArticleContents" Runat="Server">
Your article
</asp:Content>
<asp:Content ID="sidebar" ContentPlaceHolderID="ArticleSidebar" Runat="Server">
Your sidebar
</asp:Content>
If you want some manageability in the case of your site getting larger and needing more of these custom sidebars then I would not put anything beyond standard layout in the master page.
What is wrong with having an additional ContentPlaceHolder in the side bar and just adding the content into Content controls on each content page?
Your approach seems overly complex to me.
You could also put that additional code into a user control (or two). The content page would then include the user control appropriate to that page for the right sidebar.

Resources