how to style a tooltip of asp:image - c#

I'm planning to apply a css on ToolTip attribute of asp:Image but it's not working. This is what I've tried so far.
<asp:Image ID="sampleimage" runat="server"
ImageUrl="~/Image/questionmark.png" ToolTip='<%# Eval("NAME") %>'
CssClass="tooltips" />
^ the text on tooltip shows but the css is not. It only has a white
background color.
.tooltips
{
background-color: Green;
width:150px;
height:20px;
}
This is from my stylesheet from other folders.
I'm totally new at using CSS. Any form of instructions will help. Thank you

You can not style tooltips with CSS only, because they are rendered by the browser, not your web page.
But you can use a JS library to render custom tooltips (which allow custom styling).
I like to use qTip2.

Related

Is it possible to add tools in the toolbar and designed in CSS in a ASP.net (C#) project?

I know this might sound kinda stupid, but is it possible to set buttons, textbox etc etc.. in toolbox in visual studio 2015. but making the design in CSS?
I know you can give the same button the exact style form with CssClass="yourclass". But was thinking for this, and google didn't help me much.
ASP.Net controls render as HTML, so you can use CSS just as you would in any other circumstance.
Using element-based selectors:
input[type="text"] {
color: red;
}
<asp:Textbox runat="server" Text="This text is red!"></asp:TextBox>
Using ID selectors:
If you wanted to use specific IDs, it gets slightly trickier. ASP.Net controls do not render with their assigned IDs. You can circumvent this by applying ClientIDMode="Static" to your ASP elements:
#myTextbox {
color: red;
}
<asp:TextBox runat="server" id="myTextbox" ClientIDMode="static"></asp:TextBox>
It's important to note that you cannot use this for repeated elements (Gridview controls, repeater controls, etc), because element IDs must be unique.
Using class selectors:
Or, as you mentioned, you could use CssClass:
.textbox {
color: red;
}
<asp:TextBox runat="server" CssClass="textbox"></asp:TextBox>

How to make image visible in C#

I declared an picture in my ASP.NET and set it to hidden by default with style="visbility:hidden;". Is there anyway to access this image from the C# and change its visibility? Here is the img line from the ASP.NET:
<img src="canoe.png" alt="Boat Trailer" height="350px" width="600px" id="canoe" style="float:right; margin-right: 100px; visibility:hidden;" />
Use ASP:Image instead.
<ASP:Image id="myImage" Visibile="False" ImgUrl="link" runat="server">
Then you can access it in the backend with:
myImage.Visible = true;
If it is just server side to control the image visibility, just use,
<asp:Image ID="Image1" runat="server" Visible="false" />
You'll need to make this into a server tag first by adding runat='server' and an id. Then you can change its properties before the page loads like so:
<IMG ID>.Style["visibility"] = "visible";
replacing with the ID of your element.
Note about other answers: C# Visibility property will not change the CSS visibility but will actually remove or add the element, if you simply change that while the element is still set to visibility: hidden then it will still not be visible
Discalimer, this is an untested solution, you may have to check the syntax on the use of the Style property
Option 1
You can change it on the server side by adding an ID attribute and runat='server'.
Option 2
You can use an ASP.NET Image control and apply your changes there.
<asp:Image id="myimg" runat='server'.../>
HOWEVER, if you go with this option, you should still use CSS/Javascript to show/hide your image since setting Visible='false' on a server side control will prevent the HTML from rendering altogether which I doubt is the output your are expecting.
If you are performing this logic on the server side, why do you need to render the image as hidden? If you are showing the image based on user input then you should do it on client side Javascript.

Aligning html inputs on same line 2

I have the same behavior from many similar questions here.
But I tried anything and nothing happens to me.
I have 2 html controls. One anchor tag and a input button.
I applied vertical-align:top; float:right; display:inline-block; independently and together and nothing happens.
When I click on Close, I see a shadow like a button! I want them inline both controls
At the end of table I incluided a Div like this.
<div style="float:right;">
<asp:Button ID="btnInput" runat="server" Text="Add selected"></asp:Button>Close
</div>
You need to set a width for each element when you make them display:inline-block, otherwise they default to 100%.
Here is a jsFiddle with the closest equivalent markup I could make. (asp buttons don't work)
As Dolchio said, every element must have display: inline-block for this to work. Note that your float:right will not achieve anything helpful in this scenario.
Try adding the CssClass attribute to the asp button and styling that class.
So it would look like <asp:Button ID="btnInput" runat="server" CssClass="myButton" Text="Add selected"></asp> and in your css myButton{display:inline-block,vertical-align: top, width: 200px substitute width for whatever the width of the button is (not entirely familiar with asp buttons and their implied widths).

Asp.net ImageButton set to visible = false. Still shows grey border

I am using an asp.net image button control. On page load I have the button set to:
imgbtn.visible = false;
It's not showing the image. However it still displays a gray border rectangle where the button should be. I have also tried setting a style of
border : none;
It still shows a grey rectangle where the button should be.
Is this normal?
Is there a work around?
If you are hiding the image using javascript, try setting the css style display to 'none':
imgbtn.style.display = 'none';
If you don't care keeping the border, directly in your ASP.net page,
Set it like that :
<asp:Image ID="image1" runat="server" Border="0" />
Or;
<asp:Image ID="image1" runat="server" BorderStyle="None" BorderWidth="0" />
If you want to keep borders, just do the same stuff when setting your image visible = false; in your code-behind.

System.Web.UI.WebControls.TextBox multiline border [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Default textbox border-style and width
I have some TextBox on my page that should be red bordered from the code behind.
But the Multiline TextBox that present a vertica scrollbar, does not show the border from its side.
Here is my code that set the border:
foreach (var str in idsRequired)
{
var ctrl = (WebControl)FindControl(str);
if (ctrl != null)
ctrl.Style.Add(HtmlTextWriterStyle.BorderColor, "red");
}
I get controls by ID and the set theyr border.
Question is: how can i correctly border all the TextBox control?
EDIT
I finnaly end up with setting the border style to 2px and the right border appear. As you can see here:
How can you explain this?
As an advice, try to delegate the style of your controls to CSS files or ASP.Net themes. Why? Because you usually would want to reuse the same style across your website and imagine when you want to change the style again (which in a real application happens a lot), you would have to edit your code directly potentially introducing some undesired bugs, so avoid this and just separate your design from your code
You could declare the style in a CSS file and just import it to your page:
Using CSS
.txtWithRedBorder
{
border-style: solid;
border-color: #FF0000;
}
In your control
<asp:TextBox runat="server" Rows="5" TextMode="MultiLine" CssClass="txtWithRedBorder" />
Remember to place your CSS file under the Theme folder and add the following directive to the page to import automatically all the CSS files to your page
<%# Page Theme="Theme1"....
Or you could create an ASP.Net theme to accomplish the same effect:
<%# Page Theme="Theme1"....
<asp:TextBox runat="server" Rows="5" SkinID="someSkinID" TextMode="MultiLine" />
In your skin file:
<asp:TextBox runat="server" BorderColor="Red" BorderStyle="Solid" SkinID="someSkinID" />
Remember you need to specify the theme:
And this is the result

Categories