I have button in my user control like
<button class="show-form-button" runat="server" ID="btnShow">Please submit<span class="icon-down"></span></button>
In my code behind I am setting text of button but it is somehow removing span class when page is rendered
btnShow.InnerText = "Submitted";
How do I retain span class?
Innertext will replace the entire contents of the tag with the supplied text. To retain the icon, replace the inner HTML with "Submitted<span class='icon-down'></span>"
Related
I have an aspx page with 2 panels (C# code-behind), (Panel1 & Panel2). Inside Panel1 I load an HTML page. Inside Panel2 there is an aspx textbox. I want to select some text of the HTML page in Panel1 and send it to the textbox of Panel2. Would you please say how to do it?
If you know what part you want to select, assign it an ID and a runat="server" value, then you will be able to access it from the code.
For example:
If you have something like this in your HTML:
<div id="divForCode" runat="server"></div>
Then you can access the contents of the div in code-behind using
divForCode.InnerHTML;
and
divForCode.InnerText;
So all you would need to do is send it to the textbox (myTextBox.Text = divForCode.InnerHTML; or myTextBox.Text = divForCode.InnerHtml;)
Sorry I had to post this as an answer, I don't have enough reputation to comment.
In winforms, I have something similar to a HTML editor where a textbox control is used to write Html code and a browser control to display a preview.
I am trying to set an InnerHtml property of a HTMLElement with something like this:
htmlElement.InnerHtml = txtCode.Text;
The problem is when assigning a string like:
"<a href='/foo/bar.aspx'>Click Here</a>"
htmlElement.InnerHtml returns:
"Click Here"
The HTML code of the InnerHtml property is saved in a file and the file is used to render content in a website which renders and invalid link.
Is there any way to avoid this behavior of the InnerHtml property, without saving the text directly from the textbox?
My only idea is to delete the text node child of the <a> element, and then append a newly-created text node with your text. This might work around whatever process is interfering with your assignment of InnerHtml.
As a workaround you can try to put script block in your txtCode:
<script>document.write("<a href='/foo/bar.aspx'>Click Here</a>")</script>
I have a ASP.net page with Buttons,text boxes, anchor tags.
And I want to change font dynamically in entire web site.so i have added the code in master page at Page_Load event.
this.form1.Attributes.Add("style", "font-family:DilleniaUPC;");
But the font is working for all content except text boxes and Button controls.the textbox and button are asp.net controls.So i want to implement dynamic font in all controls including button and textbox.
can any one help me?
Add a css class like in your style.css which you might be referring to in your page. A more specific way will be to use a css class and apply that class to your form elements.
button, span, input
{
font-family:DilleniaUPC;
}
first one changes whole doc, second one to show changes only changes #font, all you need is
$('document').css('font-family','DilleniaUPC');
$('document').css('font-family','Georgia');
$('#font').css('font-family','Arial');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Hello
<div id="font">Hello</div>
You can apply to entire page like this
<style type="text/css">
*{font-family:DilleniaUPC;}
</style>
I want to change css from code-behind
If I have: <asp:TextBox ID="txt" CssClass="MyClass" runat="Server" />
I can do: txt.Visible = false; to hide the textbox.
But this will free up the space that the text box txt had.
Instead I want to do something like:
txt.css("display", "none");
How can I achieve this in asp.net code behind?
Thanks
Controls have a Style property which you can use to set specific CSS rules:
txt.Style["display"] = "none";
However specifying style in the html element directly is not recommended. Instead you might want to have a class, say hide, and append it to the control's css classes:
txt.CssClass += " hide";
I have list of images stored in sql database.
i try to add it dynamic at run time .
i use "InnerHtml"
i create dive tag and want to add the image list in the div tag
HTML:
<div runat=server class="ws_images" id="List_Slide">
C#
List_Slide.InnerHtml = "<li><img src=data1/images/31.jpg alt=31 title=31 id=wows1_0/></li>"
can you help me ?
It looks like you are using ASP.NET web forms.
What you can do is drop a asp:PlaceHolder control onto your page then add Literal controls in there that contain your image HTML code.
<asp:PlaceHolder id="ImagePlaceHolder" runat="server"/>
..
..
In code behind:
var literal = new LiteralControl("<li><img src=data1/images/31.jpg alt=31 title=31 id=wows1_0/></li>");
ImagePlaceHolder.Controls.Add(literal);
PlaceHolder does not render any HTML tags so if you want you can put your div tag inside the LiteralControl.