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

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.

Related

how to style a tooltip of asp:image

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.

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.

How to show and hide html fieldset And also Set legend text from Asp.Net Code behind

I have a filedset and legend inside that with "some text" and inside this fieldset i have a GRID
I have 2 questions
How to show ? hide html filedset from code behind, i tried the following way to show and hide the field set
a) set runat="server"--but it didnt work
b) i pasted the fieldset inside an asp.net panel and tried to show/hide the panel, it
also didnt work
How to set text for legend from code behind , ie I want to set
"some text" + Value_Form_Code Behind AS leged text
Note :I am using "Rad Ajax Manager" and Rad Ajax LoadingPanel
<asp:Panel ID="Panel1" runat="server" >
<fieldlset>
<legend><asp:Label id="Label1" runat="server" /></legend>
</fieldset>
</asp:Panel>
How to show /hide html filedset from code behind ?
Panel1.Visible = true; // or false
How to set text for legend from code behind , ie I want to set "some text" + Value_Form_Code Behind AS legend text ?
Label1.Text = String.Format("some text {0}",Value_Form_Code);
it should also be possible to add an ID and runat="server" to your fieldset and control visibility through code-behind. Just remember to write 'ID' in upper letters.
<fieldset ID="myFieldset" runat="server">
You won't be able to control the legend text, unless you give it an ID and runat itself. But visibility is absolutely possible.
The upside of this approach is: no needless html markup (Panel would be extra div).
The downside: fieldsets are not really asp-controls, so some things might give you exceptions, so use carefully.
I use this approach only when I want to prevent controls from rendering at all in certain cases (visibility does that).
1: I think you should put your fieldset inside an asp:panel and then hide/show the panel from your code-behind. This will automatically hide/show your fieldset.
2: As far as setting the legend text is concerned, just set the legend with runat="server" and set the code from codebehind.
When you set the 'GroupingText' property of the asp:panel control then It will render as the 'fieldset' tag in HTML and whatever set in the 'GroupingText' property value is rendered as the <legend> tag.
I think following code will help you as per your requirement.
For Design side,
<asp:Panel runat="server" ID="Panel1" GroupingText="This is legend">
<h4>Your Content Goes Here</h4>
</asp:Panel>
<br />
<asp:Button ID="btnHidePanel" runat="server" Text ="Hide FieldSet" onclick="btnHidePanel_Click" />
<asp:Button ID="btnShowPanel" runat="server" Text ="Show FieldSet" onclick="btnShowPanel_Click" Visible="false" />
For Code-behind try this,
protected void btnHidePanel_Click(object sender, EventArgs e)
{
Panel1.Visible = false;
btnHidePanel.Visible = false;
btnShowPanel.Visible = true;
}
protected void btnShowPanel_Click(object sender, EventArgs e)
{
Panel1.Visible = true;
Panel1.GroupingText = "This Legend Text Has been Changed";
btnHidePanel.Visible = true;
btnShowPanel.Visible = false;
}

Wrapping Text in a Button Text Field

I have been trying to wrap text in the Text Field of the asp button control.
Suppose I have a long file name which is kept in the text field of text box. Now if I do not set the width of the button it can grow to 200px. But I want the width to be 100 px and the text to be wrapped in the text field or I can set the text to be multi-line.
Replace space with
Try following code
<asp:Button ID="Button1" runat="server" Text="Button
Button
Button
Button" Width="100px" Height="200px" />
One link from comment leads to this solution:
<asp:Button ID="btnSubmitBatch" runat="server" Text="Submit&#10Batch" Font-Bold="true" />
But this doesn't work in Opera.
Set width of the button to 100px, and increase the height of the button.
If required, you can also decrease the padding of the button, so that the text fits-in.
Update:
What you can do then is a bit tricky, but works for me.
Make a div styled like a button, put "width:100px;height:auto" in CSS. And make the real button display:none in CSS.
Write a click event for the div, and click the real button manually from there.
$("#divButton").click(function () {
$("#btnReal").click();
});
Hope it helps :)
c#:(in the code behind on cs page)
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine("Text1");
sb.AppendLine("Text2");
BtnID.Text = sb.ToString();
You need to use CSS to achieve this.
<asp:Button ID="btn" runat="server" Text="This is some really long text that I want inside the button" CssClass="wrap" />
And now the CSS
<style type="text/css">
.wrap
{
white-space:normal;
}

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