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>
Related
[enter image description here][1]Help!
I have two svg image buttons on my page. On the page load I am displaying one of the two buttons based on the value in the DB . and I have jquery to hide that button and show another one on button click from UI. I cannot show another button after hide.
both buttons are in a single span class.
The visibility property can't be block. You should use visible instead.
Have a look at the documentation for more about this property.
EDIT
If that can help... Here is an example showing both hidden and visible for the visibility attribute...
// That is executed on load.
$("#btnXX").css("visibility", "visible");
$("#btnYY").css("visibility", "hidden");
// Handler for the toggle button.
$("#toggle").on("click", function(){
$(this).toggleClass("active");
if($(this).hasClass("active")){
$("#btnXX").css("visibility", "hidden");
$("#btnYY").css("visibility", "visible");
}else{
$("#btnXX").css("visibility", "visible");
$("#btnYY").css("visibility", "hidden");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btnXX">XX</button><button id="btnYY">YY</button><br>
<br>
<button id="toggle">Toggle it</button>
I figured it out. My back end code was using property btnXX.Visible = false, Changing it to display:none fixed my issue.
If you don't want to render the control at all in certain situations, set Visible="false". Since it keeps the control's HTML out of the page, slightly but if you want to show the control via Ajax/etc, this won't work and display:none css should be used
I have 2 asp:RadioButton that are unchecked when the page is loaded. When one is checked, I want to change the font-weight to bold in client script. I tried:
radio1.style.fontWeight = 'bold';
but it didn't work.
You can access the the css class using the attributes property. I am assuming radio1 is the id if so you could modify your c# code to
radio1.Attributes["class"] = "newCssClassName";
I personally have never modified a single property of css using c#. To do that I have always used something like jQuery.
Try to create a new css class such as
.rbSelected
{
font-weight:bold;
{
And then toggle them accordingly ( your css property should be font-weight not fontWeight)
Also a word of warning with controls such as radio buttons and checkboxes the browser will override your styling in most cases. Each browser will render the control differently regardless of what style(s) you apply. If you are looking for something custom you may need to create your own control/element (Such as an image/element that looks like a checkbox but has manages states handled in code)
For bold
$("#YourElementID").css("font-weight","bolder");
For regular
$("#YourElementID").css("font-weight","normal");
You can create a function with this lines to toggle the font-weight. To call the javascript function from the server side controls use:
radio.Attributes.Add("onclick","functionname()");
This will add the functionname to the onclick event when the radio button is rendered to the browser.
I want to load HTML content in a panel when a button is clicked. The content is generated from the c# code by fetching the database.
Currently I have to load the content on page load in the panel and make panel visible on button click. But that makes the website speed very low. So please tell how can I load html content on demand in panel?
The code to be written in the panel on button click should be this:
<p><%=databaseFuncs.getName() %></p>
So as you can see I want to things to happen on Button Click: First the C# code should be executed than it should be encapsulated in paragraph tag and then written to the panel. One by one for all database rows this should be repeated. Please help.
Also note than I don't want to use custom asp.net controls.
Just make the
databaseFuncs
public and
databaseFuncs.getName()
public and your code should work...
If the code is inside runat="server" then just use '#' instead of '='
i have made a page in asp.net, i have a costing calculator which has more than 50 fields, dependent on each other, one is the result of previous two and like that, i want my page to be printed in a well manner, and the header of the page which is in master page should not be in print, also the color schemes i want to adjust, let me know the best solution for this which .net provides
Put the content inside <div id="divid">YOUR CONTENT NEEDS TO BE PRINTED</div>
Then call the javascript function on button click which will print the selected area or only html of div. pass the id of div on calling javascript function.
function CallPrint(var strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','letf=10,top=10,width="450",height="250",toolbar=1,scrollbars=1,status=0');
WinPrint.document.write("<html><head><LINK rel=\"stylesheet\" type\"text/css\" href=\"css/print.css\" media=\"print\"><LINK rel=\"stylesheet\" type\"text/css\" href=\"css/print.css\" media=\"screen\"></head><body>");
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.write("</body></html>");
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
return false;
}
Call CallPrint('DivGrid');" on onclick() of button or use below: but.Attributes.Add("OnClick", "return CallPrint('DivGrid');");
Nothing to do with .Net and everything to do with a print stylesheet. You can create a stylesheet which will only work for when the page is printed. And you can change everything from what displays to postion to colours.
Use:
<LINK rel="stylesheet" type"text/css" href="print.css" media="print">
Note media="print" means it'll be used for printed pages.
I know that question has been asked a long time ago, however there is no accepted suggestion. So here my approach for friendly print version when using Master page.
Create an empty master page (PrintVersion.Master) to serv as print version. Add what ever you need to be print (like logos) if anything to that master page.
from your content page, add a print link with target blank. Make the href to load the current page. From the href add a querystring so you can capture it from your content page preinit event.
From your content page preinit event detect if the querystring to print exists, then specify the blank master page like: MasterPageFile = "~/Ful/Path/of/your/PrintVersion.Master"
Optional, on the PrintVersion.Master on document.ready call: window.print(); The browser print dialog will automatically open.
You can make a new printable page version, which doesn't include a header. This version can also have the layout you need.
I specifically want to add the style of background-color to the <body> tag of a master page, from the code behind (C#) of a content page that uses that master page.
I have different content pages that need to make the master page has different colors depending on which content page is loaded, so that the master page matches the content page's theme.
I have a solution below:
I'm looking for something more like:
Master.Attributes.Add("style", "background-color: 2e6095");
Inside of the page load function of the content page. But I can't get the above line to work. I only need to change the background-color for the <body> tag of the page.
What I would do for the particular case is:
i. Define the body as a server side control
<body runat="server" id="masterpageBody">
ii. In your content aspx page, register the MasterPage with the register:
<% MasterPageFile="..." %>
iii. In the Content Page, you can now simply use
Master.FindControl("masterpageBody")
and have access to the control. Now, you can change whatever properties/style that you like!
This is what I came up with:
In the page load function:
HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("default_body");
body.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#2E6095");
Where
default_body = the id of the body tag.
I believe you are talking about a content management system. The way I have delt with this situation in the past is to either:
Allow a page/content to define an extra custom stylesheet or
Allow a page/content to define inline style tags