class name for asp input box - css

I'm a asp beginner but familiar in php.I used class for defining css in asp as two ways.I want to know which is the best way practice to use.
Way I
<asp:textbox runat="server" class="sample" id="text1"></asp:textbox>
Way II
<asp:textbox runat="server" CssClass="sample" id="text1"></asp:textbox>
Both is working for css style as
.sample{
/*some style*/
}

I would use the Way II incase asp controls and Way I incase of Html controls.
Incase of asp controls if you want to change the class based on some logic, you could in the code behind(webforms) if you are doing Way II.

Related

Css validation do not work in asp net

i cant use css validation class inside asp.net controls but all other css design works correctly for example i just need to add class="validate[required]" to make a control validation in html but the same is not working for asp.net textbox controls i tried CssClass too didnt work.
please help, thanks in advance
<asp:TextBox ID="txt_uname" runat="server" Height="25" CssClass="validate[required]"></asp:TextBox>
validate[required]
This is not a valid css class name.
This declaration means validate class will apply to those elements, which have required attribute.
Your css class
.validate[required]
{
color:Red;
}
So try this
<asp:TextBox ID="txtUsername" runat="server" CssClass="validate" required="required"></asp:TextBox>

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.

AssociatedControlID for RadListBox and RadDateTimePicker controls?

I am using RadListBox and RadDateTimePicker in a traditional C# ASP.Net 3.5 web application, and I have labels like this:
<asp:Label ID="lblStartDate" runat="server" Text="Start Date" AssociatedControlID="dtpStartDate" />
<telerik:RadDateTimePicker ID="dtpStartDate" runat="server">
</telerik:RadDateTimePicker>
The label doesn't connect to the date picker with a for attribute because the picker is a complex control and it can't work out which element to target. Telerik propose a JavaScript solution to this, but that seems unwieldy to me and also depends on client side scripting.
Is there a better way which will provide a reasonable level of accessibility? Either wrapping the Telerik solution somehow or an altogether alternative approach?
Yep, the Telerik picker is a composite control as well and similar javascript to attach the label to the date input should do the trick. To reference the input field, use the get_dateInput() property from the client API of the picker.

How to override old design with new design(using master pages)?

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.

How to set multiple cssclass name to a control with ASP.NET theming enabled?

CSS supports multiple class names:
<hwc:DropDownList ID="ddlRoomType" runat="server" class="invisible blue" EnableTheming="true" />
Skin file:
<%-- Default dropdown appearance --%>
<asp:DropDownList runat="server" CssClass="dropDownList" AutoPostBack="true"/>
And asp.net theming provides extra skinning and attribute abstraction layer for us. So i'm talking about classic css styling and asp.net theming combined scenario.
But when it comes to giving a CssClass (or class) attribute manually with asp.net theming enabled, you have to make a choice which one is to override another.
How can we combine manually entered class names with dynamic class name created by asp.net theming to generate the html output like below;
<select id="ctl00_Content_ddlRoomType" class="invisible blue dropDownList">
<option value="0">- Select Room -</option>
<option value="9">Single Room</option>
</select>
I can't find any .net theming class to override to implement another theming logic.
Any ideas? Thanks.
Combining CSS classes isn't supported by the standard runtime.
However, it should be pretty easy to add, using a control adapter. You might use a syntax something like CssClass="+dropDownList" to add the class to any existing defaults. The control adapter would look for the plus sign, and set the CssClass property accordingly.
Alternatively (and probably easier), you could override the existing classes you're interested in, and modify the CssClass property to work like you want.

Resources