How to override old design with new design(using master pages)? - asp.net

I am migrating the site from ASP.NET 1.1 to ASP.NET 3.5. I am using a new design layout with MasterPage concept. In previeous sites, some pages have UserControls. These are mixed with the old design. If I convert it using MasterPages, I am getting the old design combined with the new design. Please, can anyone help me? I am new to development.
Thanks in advance.

The way you styled/designed controls in ASP.NET 1.1 was by adding attributes to the HTML of the control, for example a text input field with a white background and red border would have been marked up like this:
<asp:TextBox ID="TextBox1" BackColor="White" BorderColor="Red" runat="server" />
If your new design is using css, the reason the user controls are still using the old design is because these styling attributes have a higher precedence than the styles in your css.
The only way to get rid of the old design is to manually open each of your user controls and delete any styling attributes from the markup.

Related

ASP.NET website, Buttons are just hyperlinks

hoping someone can help me I think I know what the issue is but I can't seem to make it work.
I have a small website written with VB web developer 2010.
I am looking to move the host company I am using but the problem I am running into is that the buttons at the top of the page:
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
<asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
</Items>
</asp:Menu>
The old host they show up fine. New host (VPS server that I do everything myself) show up as only a hyperlink.
I think that it is the version of ASP.net I compile it with, currently 3.5, but I could be wrong, I have tried multiple times to get it to work.
Any help is appreciated. Thanks!
Are you sure you copied over the CSS files that go along with the project, and that they are in a directory that has the correct permissions?
Read this link then: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.renderingmode.aspx
In particular it references a rendermode setting that you may need to set when you are changing from 3.5 or lower to 4.0
The value of the RenderingMode property determines how the menu
control renders markup for the Menu control. In ASP.NET 3.5 and
earlier versions, the Menu control uses HTML table elements and inline
styles to specify the appearance of the menu in a browser. In ASP.NET
4 and later versions, by default the Menu control uses HTML listitem
elements and cascading style sheet (CSS) styles. If you do not set
this property, the Menu control renders markup that is appropriate to
the ASP.NET version that is indicated by the
Control.RenderingCompatibility property. The Menu control uses the
following rules:
If the value of the RenderingCompatibility property is 3.5, the Menu control uses HTML table elements and inline styles.
If the value of the RenderingCompatibility property is 4.0 or greater, the Menu control uses HTML listitem elements and CSS styles.
This property is provided for backward compatibility. If the
RenderingCompatibility property indicates that you want controls to
generate HTML that is compatible with ASP.NET 4 or later, but you want
the Menu control to be an exception that uses earlier behavior, you
can set this property to Table. For example, if you have a Web page
that displays text from right to left you might want to set this
property to Table because some browsers do not display the List mode
markup properly for right-to-left text.
Solution!
Server side: change the asp.net version to 4.0 using the answer located here
In your Web.config
I had a line with this
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
Change to
<pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID"/>
Complete!
Thank you for your help E.J. without knowing it was CSS related I could not have come across the answer.

When working in Visual Studio, can the ' asp: ' portion of an element be omitted?

Situation: I have been creating webpages in HTML5/CSS3 & Javascript using Sublime 2 text editor for a year, however a college course now requires me to use Asp.Net and Visual Studio 2010. I do not use the designer because I am proficient at doing things by hand, however I find that writing asp: inside every element is time consuming and causes syntax errors when applied to some HTML 5 tags and not others.
Example HTML 5: <button id="btn" type="submit" value="Button"/>
Example Asp.net: <asp:Button ID="Button1" runat="server" Text="Button" />
Question: Can the asp: portion be omitted without effecting anything or is it required for IIS or the C# back-end functionality? What about runat="server" can that be omitted?
Google has come up dry regarding my inquiry, so any help is appreciated.
you simply cannot remove either of the two
but hear me out why, because I have a feeling you are not familiar with ASP and therefor are mistaking the meaning of the asp: and the runat="server" syntax.
first: runat="server"
this property on an element, tells the the compiler that this is actually a server side control
so a <button/> is not the same as an <button runat="server"/>
the first one is pure html, while the second one is a control, which can be bound to on the server side. .Net will give it a clientID (not to be mistaken by the ID you have to give it yourself).
second: asp:
this is a prefix, on certain elements, that tells the compiler these are ASP controls (the default controls given by the ASP.net framework). These include Buttons, TextBoxes, DropDownLists, ...
do not mistake 1 of these with a html element.
an <asp:Button id="myAspButton" runat="server"/>
is not the same as a <button id="myHtmlButton"/>
the first, is a server side control, which can be bound to (see it's runat="server" attribute), and this control renders to the browser as a <input type="submit"/> for example.
you could alter the rendering of the asp.net button class to make it return something entirely differnt if you wish.
and you are also not limited to using asp.net classes.
you can create your own controls, and put them in a custom created library
you could give those your own prefix.
if I created such a custom control, I could register a prefix for it in the web.config file,
and thus I could create a custom button extending from the original one (but with a default label in front...
<myc:CustomButton ID="myButton" Text="myButton" Label="myLabel" runat="server"/>
which could render into:
<label>myLabel</label>
<button ID="*******">myButton</button>
the asterisks are symbolizing the Unique ID it will get from the .net framework
if you want to know more on custom controls, or extending default controls
here is a step by step explanation to create custom controls, or extend from a TextBox control.
it also shows how you add a custom prefix for your controls (in the this case 'cc')
you can find more info here
The runat="server" part is required to tell .NET that it will have to render a button there (which will contain .NET specific ID for processing upon POST). Not too familiar with web forms (I started with MVC), but I would assume that the asp: part is to help distinguish between server controls and standard HTML markup.
Why not try removing it and if it breaks something, then you know it's needed. For instance if the button doesn't show up after removing it, then obviously the .NET markup parser needs it to be there in order to know that it is a place holder for a server control.

How do I make .Net Framework 4 render asp:treeview as <ul> <li>?

I have an <asp:treeview> control that looks like this:
<asp:TreeView ID="tvCategory" runat="server" CssClass="CategoryTree" NodeStyle-CssClass="TreeNode TreeNodeUDF" SelectedNodeStyle-CssClass="TreeNodeSelected TreeNodeSelectedUDF">
</asp:TreeView>
This control renders in my page as a table. Is there any way to make .NET render it as <ul><li> tags, so I can easily assign a CSS class to it? I need to change the appearance of this TreeView so that it is oriented horizontally, not vertically.
You could use the CSS control adaptors, with rendering mode not being available for the treeview control in .NET 4.0. Also see here for a similar question.
Perhaps spare yourself the trouble and go for a client side approach?

.NET replace LocalizedButton with an image

I inhereted this old .net 2.0 site and need to make this code view as an image, like a normal input type = "image" src=".." etc.
<cc1:LocalizedButton ID="btnLogin" runat="server" />
The site is precompiled, so I have no access to the code behind, and I need to keep this forms functionality.
It is VB to if that makes any difference.
Thanks in advance!
UPDATE: Code for first question: https://gist.github.com/1320856
You can use the ImageButton control

Best way to custom edit records in ASP.NET?

I'm coming from a Rails background and doing some work on a ASP.NET project (not ASP MVC). Newbie question: what's the easiest way to make a custom editor for a table of records?
For example: I have a bunch of data rows and want to change the "category" field on each -- maybe a dropdown, maybe a link, maybe the user types it in.
In Rails, I'd iterate over the rows to build a table, and would have a form for each row. The form would have an input box or dropdown, and submit the data to a controller like "/item/edit/15?category=foo" where 15 was the itemID and the new category was "foo".
I'm new to the ASP.NET model and am not sure of the "right" way to do this -- just the simplest way to get back the new data & save it off. Would I make a custom control and append it to each row? Any help appreciated.
You can REALLY cheat nowadays and take a peek at the new Dynamic Data that comes with .NET 3.5 SP1. Scott Guthrie has a blog entry demoing on how quick and easy it'll flow for you here:
http://weblogs.asp.net/scottgu/archive/2007/12/14/new-asp-net-dynamic-data-support.aspx
Without getting THAT cutting edge, I'd use the XSD generator to generate a strongly typed DataSet that coincides with the table in question. This will also generate the TableAdapter you can use to do all your CRUD statements.
From there, bind it to a DataGrid and leverage all the standard templates/events involved with that, such as EditIndex, SelectedIndex, RowEditing, RowUpdated, etc.
I've been doing this since the early 1.0 days of .NET and this kind of functionality has only gotten more and more streamlined with every update of the Framework.
EDIT: I want to give a quick nod to the Matt Berseth blog as well. I've been following a lot of his stuff for a while now and it is great!
There are a few controls that will do this for you, with varying levels of complexity depending on their relative flexibility.
The traditional way to do this would be the DataGrid control, which gives you a table layout. If you want something with more flexibility in appearance, the DataList and ListView controls also have built-in support for editing, inserting or deleting fields as well.
Check out Matt Berseth's blog for some excellent examples of asp.net controls in action.
Thanks for the answers guys. It looks like customizing the DataGrid is the way to go. For any ASP.NET newbies, here's what I'm doing
<asp:DataGrid ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="RuleID" Visible="False" HeaderText="RuleID"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Category">
<ItemTemplate>
<!-- in case we want to display an image -->
<asp:Literal ID="litImage" runat="server">
</asp:Literal>
<asp:DropDownList ID="categoryListDropdown" runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
This creates a datagrid. We can then bind it to a data source (DataTable in my case) and use things like
foreach (DataGridItem item in this.GridView1.Items)
{
DropDownList categoryListDropdown = ((DropDownList)item.FindControl("categoryListDropdown"));
categoryListDropdown.Items.AddRange(listItems.ToArray());
}
to populate the intial dropdown in the data grid. You can also access item.Cells[0].text to get the RuleID in this case.
Notes for myself: The ASP.NET model does everything in the codebehind file. At a high level you can always iterate through GridView1.Items to get each row, and item.findControl("ControlID") to query the value stored at each item, such as after pressing an "Update" button.

Resources