I'm using a CSS file for styling, and it's working properly for all of my controls except for a label on my page. It's the only label on the page, so maybe it's a problem w/ labels in general? I'm changing the Label.Text property several times, and the text gets updated properly every time, but it's just raw, non-styled text.
I have the following style listed in my CSS file:
label.myError { font-weight:bold; font-size: 25px; color:Red; font-family: Arial }
I have the following label control on my web page:
<asp:Label ID="lblError" CssClass="myError" runat="server" />
Then, at various points in my code-behind, I change the Text on the Label like this:
lblError.Text = "Please specify a " + fieldDescription + ".";
asp.net label renders as span and not label html element. Your css specifies that the class should work with labels only
label.myError { font-weight:bold; font-size: 25px; color:Red; font-family: Arial }
you just have to change label.myError to .myError to be like
.myError { font-weight:bold; font-size: 25px; color:Red; font-family: Arial }
and isA it will work.
ASP.Net will output your label as a span. So the output would be:
<span id="lblError" class="myError">hi</span>
This is why you can't use label.myError
Related
i'm trying to fill a textbox in a webbrowser with my winform application if you guys have any idea of how should i do it.
here's the code :
<input autocomplete="number" id="number" name="number" type="tel" aria-describedby="error-for-number tooltip-for-number" data-current-field="number" class="input-placeholder-color--lvl-34 unknown" placeholder="number" style="color: rgb(51, 51, 51); font-family: "Helvetica Neue", sans-serif; padding: 0.94em 0.8em; transition: padding 0.2s ease-out;">
You can use SetAttribute method after getting the HTML element (by Id, class or name). For instance:
webBrowser.Document.GetElementById("number").SetAttribute("value", "5");
There isn't much information from your question, so I think my solution will work fine. Hope it helps!
I am having a button in my project whose text I am setting through aspx.cs page.
Here is code of button
<asp:Button ID="btnEmailRequestSummary" runat="server" OnClick="btnEmailRequestSummary_OnClick" />
Here is code from aspx.cs page
if (//condition)
{
btnEmailRequestSummary.Text = "Generate & Email - Request Summary";
}
else
{
btnEmailRequestSummary.Text = "Generate Request Summary";
}
I need a 'Summary' word to be appear on next line. I tried using <br />, \n, and also ASCII values for <br /> and \n but no luck.
EDIT : As pointed in comment this solution might not work on some browsers, please use CSS to achieve this as suggested here
declare this CSS class :
<style type="text/css">
.wrap { white-space: normal; width: 100px; }
</style>
Then in the code-behind:
btnEmailRequestSummary.Attributes.Add("class", "wrap ")
This might work on some browsers,
btnEmailRequestSummary.Text = "Generate Request
Summary";
[ampersandHash010;] character entity normally gives the new line in Button Text.
Refer this link for more Character Entity References:
Hope this helps.
You may try this
CSS:
white-space: pre;
width: 60px;
word-wrap: break-word;
With the exact text for the button being:
string.Format("Generate & Email - Request {0} Summary", Environment.NewLine);
NOTE: the spaces before and after the Environment.NewLine
I have a textbox with a spinner that allows the user to select numbers. But if a certain user is logged in then I want to disable the textbox and the spinner.
<asp:TextBox runat="server" ID="txtCreditDays" CssClass="integeronly spinner" Text="0" Width="20px"></asp:TextBox>
I used this to disable the textbox:
txtCreditDays.Enabled = false;
But the user can still click on the spinner and change the value. I need to disable the spinner to but since it is a CssClass I don't know how.
Here is the code for the spinner:
.spinner {
border: 0px solid #85B1DE !important;
font-weight:normal !important;
padding:0px !important;
background: none !important;
min-width: 60px !important;
}
I can't edit the CSS code because it is being used by other parts of the code.
You can use Replace method very simple.
txtCreditDays.CssClass= txtCreditDays.CssClass.Replace("spinner","");
I Don't know asp.net. But i can give you a logic through php.
In PHP, We do like this.
<input type="text" class="<?php if($user_loged_in){ echo "some_other_class"; } else { echo "spiner";} ?>">
Using an if statement could solve this in asp
I am using Metro UI project with my layout. I also added the font awesome into my project but when I use the metro and font awesome together, there have some issues:
<div class="tile-content icon">
<span>
<i class="fa fa-ticket fa-fw"></i>
</span>
</div>
I want to set the fa icon into Metro UI title but when I run the code, I cannot see the icon from the title:
If i only add following:
<i class="fa fa-ticket fa-fw"></i>
Everything is fine... Somebody that can help me?
I had the same problem. You need to "force" the font-awesome font:
.fa {
display: inline-block;
font-family: FontAwesome !important;
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
This block is in the font-awesome.css file and you need to add the !important so Metro UI does not override it.
If you do not want/can edit the original CSS file you should also be able to fix this by adding the following to your own CSS file:
.fa {
font-family: FontAwesome !important;
}
The reason for this problme is, that one style from Metro UI CSS does override the font-family style for the tiles and so the font-awesome font is not used anymore by default.
Is there a way to get the innerHTML of a section of the page together with all style information that is used by the elements in that section(including styles that also come from corresponding stylesheets). So that when I insert the html somewhere else It will display with original styling.
It should display with styling anyway, unless I'm missing something in your question. If you have this style:
.item { color: red; background-color: #CCC; border: solid black 1px; }
.item a { color: #300; text-decoration: none; }
.item h2 { font-size: 1.5em; }
And this HTML:
<div id="test">
<div class="item">
<h2>Cat</h2>
Details
</div>
<div class="item">
<h2>Dog</h2>
Details
</div>
</div>
Moving that HTML to another section of the code (whether copy/pasting or moving it through DOM manipulation) shouldn't matter. The styles should be applied correctly. It's just a matter of constructing your CSS in a modular way. In this case, too much specificity could be an issue.