ASP.NET C# how to Ignore certain styling in MasterPage - c#

So I created a master page which serves as the Header and Footer template for every other template, the problem however, in one of the form, I put all the HTML that I wanted, CSS and JS when I load it theres some problem with the result. I figure out the problem is caused by this code
<form id="form1" runat="server">
If I remove that code, then the output will be what I want, the problem is that I dont want to remove that code in the MasterPage, is there a way to set that the Web form that follow that masterPage will ignore the
<form id="form1" runat="server">
Thanks and have a great day

Related

Web Application Project not accessible due to form tag on every page

I have a legacy Web Application Project (WAP) that I need to ensure is accessible. This type of project has a Master Page (Site.Master) and each page (called a Web Form) inherits from that page to maintain a consistent look.
A fresh Master Page looks like below:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="First5Edmx.Site" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
You will see that the body contains a form tag, which means that every page using Site.Master as it's template will have a form on it, regardless of if it's actually a form. If you remove the form tag the project will not compile.
When I run web accessibility on my site I am getting the error "The page contains a form but there is no submit button" on every page. It is, of course, correct, but how do I make this code accessible (without re-creating the whole project in more modern technology)?
Whether or not you can make the warning disappear, remember that validators and checkers are there only to draw your attention to potential problems, but not every single message may not necessarily be a real problem.
It's especially true with accessibility checkers. They globally make good assumptions, but sometimes can't know between a misstake and something a bit odd but desired for whatever reason.
The most important with such tools is that, if you have a warning that you can't/don't want to fix, is to exactly know what it implies.
If you can live with the implications, then you can live with the warning.
To know what it implies exactly, the best is of course to make manual tests. Accessibility tools can never replace manual tests.
Coming back to your particular case, of course the tool is technically correct: a form must have a submit button.
In practice however, if a form has neither any field nor any button, it's impossible to send anything. So there will only be very few annoyance for you and for the user, if any.
You can still try two things in the pages having no real form, though:
Add the role="presentation" to the <form> as suggested in the other answer, so that screen readers won't announce a form to the user when there's nothing to fill
Add a dummy submit button, disabled and hidden with display:none so that no one can see nor click it, if you really want to make the accessibility checker happy. Note that it may cause trouble to users with custom or disabled CSS. OF course there shouldn't be any additional submit button when there's already a real one.
Think about the second item: what do you prefer ? a warnings in your tool, or a little hacky solution potentially causing trouble to 1 user out of 1000000 and maybe a few buggy pages if by misstake you leave the normal and a dummy button ?
Now that you know what the consequences might be, personally I think that it isn't worth the effort to clear the warning just to say that you ahve done it, but do as you feel it.
The role=presentation has no side effect when not using a screen reader, so you are totally safe on this one.
I'm not sure if this will still be flagged by the compiler, or whatever is throwing the error, but you can hide elements with display:none. This will also hide it from assistive tech, so if there's a tool that's flagging this as an issue, hiding it might prevent it from being flagged.
You can also try role="presentation" which basically tells assisitve tech that this element is solely for visual purposes and contains no information. It's a bit of a hack, but worth a try.
<form style="display:none" id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>

Changing HTML element's style property from code behind

I have a HTML page which is dynamically generating by server. The application has an IDE to generate and design pages then deploy the server. The server displaying this pages in an iframe. We can use all c# methods as well as Page_Load and Page_PreRender events in pages. But I can't modify source code of the asp.net page (I mean can't add runat="server").
What I want to do, finding a html tag by css class (#form1 > span) before pre-render then add a new css property in code behind.
<form id="form1" action="DocumentViewer.aspx" method="post" autocomplete="off">
<span>
<table>
<tr>
<td></td>
</tr>
</table>
</span>
Without runat="server" you cannot access the control in code behind. Best way to do it is to inject the jquery script from code behind to do the same work.
Please take a look at this answer.

<asp:Content> does not correspond with <asp:ContentPlaceholder>

My ASP.NET page was not showing the controls. It just shows that master page error
The page has one or more <asp:content> controls that do not correspond
with <asp:ContentPlaceHolder controls in the Master Page
Try setting
<title></title>
instead of
<title />
Remove comment (<%-- --%>) in the Master file, this worked for me.
All your Content controls have to reference existing ContentPlaceHolders on master page
For instance, if you have on your page
<asp:Content ContentPlaceHolderID="Header" ID="Title" runat="server">
You must have something like this on your master page
<asp:ContentPlaceHolder ID="Header" runat="server" />
ContentPlaceHolderID is the property that must match against any ContentPlaceHolder ID on master page.
The problem is that you must have a syntax error in the master.page's markup :
Ex) %²> in stead of %>
If you validate your markup, I'm sure thar this will solve your problem
PI. I has the same error & it works for me ;)

Disable feature in Master Page from Content Page

I have a Master Page for all my ASP.NET pages. It works fine for 95% of pages... Except that it also includes unwanted attributes that are included in the other 5% of pages. This causes application problems. Is it possible for Content Pages to somehow select to enable/disable a feature available in the master page? One option I can think of is for the Master Page to look at the page name and then decide what to do, but that's a bit clunky in the long run...
You can add a MasterType directive in your content page so you will have access to the master page class... and from there you can implement to enable disable features of your master page...
<%# MasterType virtualpath="~/MyMaster.master"%>
and in your code behind you will have access to the Master property as a typed class...
In your master page provide a content placeholder:
<asp:ContentPlaceHolder ID="foo" runat="server">
<div>Some default content</div>
</asp:ContentPlaceHolder>
In the 5% of the pages that don't need the default behavior override this placeholder with an empty string:
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="foo" />
The other 95% of the pages will get the common behavior.
You can access the master page directly by getting at the page and casting it to the type of your master page as below. This will couple you to the master page but the only other option I can think of is to create a key in session.
(MyMasterPage)Page.Master
Assuming that these features are represented in the asp markup of the master page, you could wrap it within a ContentPlaceHolderControl:
<asp:ContentPlaceHolder ID="OptionalContent" runat="server">
*** This is my optional content ***
</asp:ContentPlaceHolder>
In the 95% of pages where this content works, you can just not include a Content control for "OptionalContent" on your page. For the 5% where it doesn't work, you can include an empty Content control for "OptionalContent":
<asp:Content ContentPlaceHolderID="OptionalContent" runat="server"></asp:Content>

SharePoint Master Page modified SPSWC:SearchBoxEx not working correctly on each site

I have created a custom master page and have the follwoing code on the page:
<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
<SPSWC:SearchBoxEx id="SearchBox"
RegisterStyles="false"
TextBeforeDropDown=""
TextBeforeTextBox="Search"
TextBoxWidth="120"
GoImageUrl="/_layouts/images/gosearch.png"
GoImageUrlRTL="/_layouts/images/gosearch.png"
UseSiteDefaults="true"
DropDownMode = "HideScopeDD"
SuppressWebPartChrome="true"
runat="server"
WebPart="true"
__WebPartId="{07E563F9-A259-4829-920F-03829BBC14D1}"
GoImageActiveUrl="/_layouts/images/gosearch.png"
GoImageActiveUrlRTL="/_layouts/images/gosearch.png"/>
</asp:ContentPlaceHolder>
On one site this code works correctly and on another it does not work and the default search box apears. I can not work out why this is happening. Any ideas?
The content in the contentplaceholder "PlaceHolderSearchArea" can be overwritten by a <asp:Content /> element in a page layout. So check the page layouts you are using for the existance of an <asp:Content/> with the placeholder id "PlaceHolderSearchArea".

Categories