I am facing a strange issue. I have a html page whose design is perfect but when I am copying the same to aspx then design got distorted. Now, when I removed
<form id="form1" runat="server"> and <head runat="server">
attribute then design got corrected.
I am not sure why this has happened and how can I fix that because I don't think it's a good idea to remove form tag from aspx page
I fixed this issue.
Some of my CSS was referring to ID, when I changed it to class it started working as per my expectation.
It is an important note for all ASP.NET webform developers: "Do styling with class only"
Ex: #Myclass
{
height:10px;
}
<div id="divId" class="MyClass"></div>
Check your .css file(s) of your application where aspx resides. There must be styles defined for form element.
Better way to check style relaed issues is to use browser's developer tools.
Related
Field renderer was working fine on mvc but now we moved to web pages, and i am converting my layouts & renderings to webpages but field renderer are not working in page editor mode but in published mode looking fine. page editor screen shot is attached.
Field rendered as
<sc:Text ID="Title" Item="<%# ((Sitecore.Data.Items.Item)Container.DataItem) %>" Field="Navigation Title" runat="server" />
and
<%# FieldRenderer.Render(Container.DataItem as Sitecore.Data.Items.Item, "Navigation Title") %>
tryied both but same result :) any help would be appreciated.
I have av vague memory of seeing this error before. If I remember right, the problem was that Sitecore couldn't do all its Page Editor magic properly by inserting scripts etc into the html header and body. It's worth I try to just verify that your layout forms a proper html document and having the head and a form accessible from the server, such as this:
<!DOCTYPE html>
<html>
<head runat="server">
</head>
<body>
<form runat="server">
</form>
</body>
</html>
I was a long time ago I used webforms with Sitecore, so I don't remember exactly what components Sitecore hooks into in order to make the editor works, but having a page structure as above should be good to go.
Hope it helps
// Mikael
I got a user control that I want to style with a larger bunch of CSS. Because the control can be implemented several times into the website as well as the CSS can vary on dependent properties of the user control, I cannot use a global extern CSS. So I need a scoped CSS part that comes with the control itself. Unfortunately HTML5 scoped styles are not common yet, so this is out of question.
My idea: I want to use a style tag within my root asp:Panel of my user control to style specific parts of my control. With the generated client ID of the parent container I can define a strict scope of the CSS. I optain the generated ID with a server variable:
<asp:Panel ID="pRoot" runat="server">
<style type="text/css">
#<%= this.pRoot.ClientID %> .myClass {
background-color: magenta;
width: 100px;
height: 100px;
}
</style>
<asp:Panel ID="pTest" runat="server" CssClass="myClass" />
</asp:Panel>
Now this will not work as it assumes <%= this.pRoot.ClientID %> is CSS, too.
I know a static parent ID or code behind mechanics can solve this specific case, anyways.
So I just wonder:
Is there a way to get a server sided variable into my style part of my markup without using code behind?
EDIT: It turned out, that the above example will work. Visual Studio just tells me the above example is not valid HTML. Annoying error, makes the same problems just as using server sided variables in JavaScript. Microsoft, something has to be done about that.
Any idea to get rid of this error?
You can bind to page level methods and properties:
<%# propertyName %>
<%# MethodName() %>
both implemented in your page class.
The ID could come from server side anyway.
I have a div element in my HTML. I added a id and runat attributes to the element:
<div id="footer" runat="server">
After rendering, viewing the HTML shows:
<div id="ctl00_footer">
However, I cannot access it from the page's .aspx.cs code:
footer.InnerHtml += "test";
How do I access that element from the C# code?
you can use FindControl("footer"), and cast it to HtmlGenericControl.
HtmlGenericControl footer = (HtmlGenericControl)FindControl("footer")
One of the reasons can be that you don't have designer file for that page. So you can't access element by it's ID.
Just add class with name [your page name].aspx.designer.cs, open it, remove all code, save it, go to your view and click save - designer must generate code of all elements from your view. After this you can access element by ID.
There should be no problem accessing <div id="footer" runat="server"></div> the way you are doing. Strange though, my generated markup keeps the div id unchanged as footer.
Make sure you don't have any compile errors, and that you can access other elements running server-side in the same scope you are trying to access this div.
You need to set the ClientIDMode property of the page or control to Static:
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx
This will prevent the "ctl00_" from being appended to the ID which is what is causing you the problem.
I have encountered this problem before. You may have the target div inside another div that does not have the runat="server" attribute. All nested divs should have the runat attribute in order to be able to access the inner elements.
<div id="divContainer" runat="Server">
<div id="yourDiv" runat="Server">
</div>
If you're going to code ASP.NET and you want to access the control from the server-side, you may as well use the provided controls.
Use a Panel instead of a Div. The ASP:Panel control renders as a div in the generated html anyway. The Panel doesn't have a .Text property, but you can add controls to it from code-behind (such as a Label or a LiteralControl.
Is there possibly a chance that the page was copy/pasted when being created? If so, make absolutely sure that all references to the old page are changed to the name of the new page. I've done this before within the code at the top of the ASPX page, as well as the namespace of the designer page.
I had the same problem and found out that due to a "copy" and "paste" my function had a "static" declaration.
Removed it since static functions can't access non-static identifiers and it was fixed.
I have the same issue.
My solution was to have 'ID' instead of 'id' for the div element (i.e. the casing was the reason).
I'm sure this has a simple answer, but I can't find it. I need to create an ASP.NET control that doesn't render anything. This is similar to an ObjectDataSource that shows up as a gray box in the aspx design mode. Until now I have only created controls that DO render and I can't find what property, attribute, override, etc. will prevent rendering during design. Any pointers?
Edit: Just to clarify, by simply inheriting from Control, it renders [ TypeName "ControlId" ]. I want it to render as the gray box that says TypeName - ControlId.
OK well I played around with it and you're right, it's not trivial.
Turns out VS doesn't actually execute .ascx user control code when it's shown in the designer, it only parses the markup, so you can't conditionally change the control.
However, that limitation is not active when you use a real ASP.NET Server Control. Just add a new project to your solution of that type and in your .cs file, overrite RenderContents:
protected override void RenderContents(HtmlTextWriter output)
{
if (DesignMode)
output.Write("<table style='border-color:Black;background-color:Gray'><tr><td width=300px height=100px style='vertical-align:middle;text-align:center'>I'm your design time box.</td></tr></table>");
else
output.Write("Runtime text lalala");
}
Then in your .aspx file, you just add the control:
<body>
<form id="form1" runat="server">
<div>
<cc1:ServerControl1 ID="ServerControl1" runat="server" />
</div>
</form>
</body>
Design time result:
Run time result:
The property you are looking for is called DesignMode
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.