Include CSS Content page in Masterpage ASP.NET - css

why i cannot adding css Content Page in Master Page Asp.Net.
i cannot change..
<asp:TextBox ID="name" runat="server"></asp:TextBox>
then i use css
#name {
width:300px;
height: 300px;
}
but he did not change.
anyone can help me resolve this?

By default server object ID's aren't rendered exactly the same. You should either use a class instead or set clientidmode to static for the textbox.
If you view the source on the rendered page and look for that textbox, you'll find the ID is probably a few names separated by an underscore.
Here is the same markup with a static client id.
<asp:TextBox ID="name" runat="server" ClientIDMode="static"></asp:TextBox>
Please note that you shouldn't do this for any control that you plan to repeat on a page.
In that case you should use a class.

You have to use this CSS using Class
because When Server control render in page then Their ID is Unique that generate by IIS foloowd by contant page Holder Name
means
<asp:TextBox ID="name" runat="server"></asp:TextBox>
this will genrate
<input id="ContantPlaceholderName_name" name="ContantPlaceholderName_name"/>
so use class name is better option

Related

Master Page Changes ID of Elements

I use JavaScript and am trying to use more JQuery. Anyway I never liked the way Master Pages change the ID's of my elements. So when I use getElementById("MyElement") it fails to find the element. So I hit F5 and do a view source and then copy the new ID of the element and it works.
My Question...
Is there a better way to do this?
Set the ClientIDMode and ClientID of your server control, like this:
<asp:TextBox ID="TextBox1" runat="server" ClientIDMode="Static" ClientID="MyTextBox" />
Now you can reference the textbox in jQuery or plain old JavaScript via the MyTextBox ID selector.

How to set the name attribute of an element in ASP.NET which is not equal to its ID attribute

I have a code which I have to use HTML elements instead of ASP.NET elements. So because I want to have access to the elements from CodeBehind I've set all of their attributes to runat=server.
As you know ASP.NET changes the name attribute of elements to something like CT100$MainContent$IDNameOfThatElement. How can I prevent ASP.NET to change it? Cuz I have to have some other names because of JQuery stuff...
For example ASP.NET changes the name attribute from required to CT100$MainContent$PaymentCode in the following code:
<div class="field">
<input type="text" runat="server" name="required" id="PaymentCode" />
</div>
Thanx in advance.
You have to add ClientIDMode="Static"
Example:
<asp:Panel ID="myPanel" runat="server" ClientIDMode="Static">
</asp:Panel>
As far as I know you can't override the name attribute without jumping through some hoops. What you can do is create a controlAdapter that can control which attributes will be rendered and how.
Have a look at this answer for an idea about how to accomplish your goal.

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>

How do I put hint in a asp:textbox

How do I put a hint/placeholder inside a asp:TextBox? When I say a hint I mean some text which disappears when the user clicks on it. Is there a way to achieve the same using html / css?
The placeholder attribute
You're looking for the placeholder attribute. Use it like any other attribute inside your ASP.net control:
<asp:textbox id="txtWithHint" placeholder="hint" runat="server"/>
Don't bother about your IDE (i.e. Visual Studio) maybe not knowing the attribute. Attributes which are not registered with ASP.net are passed through and rendered as is. So the above code (basically) renders to:
<input type="text" placeholder="hint"/>
Using placeholder in resources
A fine way of applying the hint to the control is using resources. This way you may have localized hints. Let's say you have an index.aspx file, your App_LocalResources/index.aspx.resx file contains
<data name="WithHint.placeholder">
<value>hint</value>
</data>
and your control looks like
<asp:textbox id="txtWithHint" meta:resourcekey="WithHint" runat="server"/>
the rendered result will look the same as the one in the chapter above.
Add attribute in code behind
Like any other attribute you can add the placeholder to the AttributeCollection:
txtWithHint.Attributes.Add("placeholder", "hint");
Just write like this:
<asp:TextBox ID="TextBox1" runat="server" placeholder="hi test"></asp:TextBox>
<asp:TextBox runat="server" ID="txtPassword" placeholder="Password">
This will work you might some time feel that it is not working due to Intellisence not showing placeholder
Adding placeholder attributes from code-behind:
txtFilterTerm.Attributes.Add("placeholder", "Filter" + Filter.Name);
Or
txtFilterTerm.Attributes["placeholder"] = "Filter" + Filter.Name;
Adding placeholder attributes from aspx Page
<asp:TextBox type="text" runat="server" id="txtFilterTerm" placeholder="Filter" />
Or
<input type="text" id="txtFilterTerm" placeholder="Filter"/>
asp:TextBox ID="txtName" placeholder="any text here"

Add a class along with class specified in the skin

We are using themes to style our control.
For textbox we have added like this in the skin
<asp:TextBox runat="server" CssClass="txt edit_txt" />
Now in some cases, we want to add another class along with this 2 classes.
when we added a textbox like this in aspx
<asp:TextBox ID="txtnameE" runat="server" MaxLength="30" CssClass="RequiredCheckClass"></asp:TextBox>
On rendering it didn't take the "RequiredCheckClass" class, but only the other 2 classes specified in the skin.
So is there any way to add a class along with the classes specified in the skin from an aspx page.
PS : now i am going to use #Curt suggestion or will use EnableTheming=false and will add all the required classes to this control. Please update if anyone got any other idea other than these....
One option would be to create another TextBox control in the Skin file like:
<asp:TextBox SkinID="Required" runat="server" CssClass="txt edit_txt RequiredCheckClass" />
And then use the following in your markup file:
<asp:TextBox ID="txtnameE" runat="server" MaxLength="30" SkinID="Required"></asp:TextBox>
Other than that I'm not sure. I've always avoided ASP.NET Themes since I found out how restrictive they are.
You can use the "class" property - just like you use it in a regular HTML element.
thats the bypass that i am using.
<asp:TextBox SkinID="Required" runat="server" class="RequiredCheckClass" CssClass="txt edit_txt" />

Resources