views:

102

answers:

6

Does anyone have any ideas how to create a function that resizes text on a page dynamically without the use of JavaScript? I'm using CMS based on C#?

Is it possible with CSS only? if it's not possible then i want to do with javascript like this page http://demo.joomla.org/1.5/?template=beez and as a fallback want to user server side solution which this page hasn't http://demo.joomla.org/1.5/?template=beez

+1  A: 

Without javascript? Well, guess you will have to perform a postback onchange, then perform resize in your codebeind. Not very user friendly though.

I doubt CSS can do that.

o.k.w
isn't onchange used by javascript only?
jao
@jao: Oh yah, I missed that. You are right. Well, guess I can't offer 100% javascript free solution. :P
o.k.w
can we this thing possible with server side programming and javascript
metal-gear-solid
@Jitendra: With javascript alone, you will be able to do it. Check this out http://jsbin.com/ahaxe
o.k.w
Found a similar SO post: http://stackoverflow.com/questions/1288297/jquery-auto-size-text-input-not-textarea
o.k.w
+1  A: 

I think you are misunderstanding something, you want a C# function for something that is fundamentally client side? Do you want to do it after the page has loaded or before? You can resize text on a page with CSS easily.

body{ font-size:60%; }
Sam152
A: 

If you are looking for say 3 sizes (standard, large, huge) then the way I've done this is to create the visual elements as ImageButtons or CSS'ed Buttons to style them to fit the design.

You can then hold the body{font-size:1em;} outside of the CSS includes (but before it in the head section) within a Literal to honor the browser defaults by default. When the postback occurs you can adjust the literal accordingly - e.g. large would be adjusted to body{font-size:1.5em}.

litFontSize.Text = "body{font-size:1.5em;}"

You do need to check that the body font-size is being inhereted throughout though, cross browser - form text for one will need independent definiton in my experience.

Chris
+1  A: 

You could create 3 links:

<a href="?size=medium">A</a> <a href="?size=large">A</a> <a href="?size=x-large">A</a>

Then on postback, use the value of the 'size' query string attribute as a CSS font-size value. something like (pseudocode)

// aspx
<div style="font-size:<%= getsize(); %>"> ...

// code behind
getsize(){
  return Request.QueryString["size"];
}
echo
?size="><script>alert('whoopsie');</script>
Sam152
Hmm? I'm not sure I get your drift there, Sam152.
echo
Answer is: XSS;)
el.pescado
+1  A: 

If you are getting size from database then you can do one thing: Create a panel and put all controls in it and set size dynamically.

See following for more details:
http://asp-net-example.blogspot.com/2009/04/how-to-set-change-panel-font-size.html

Brij
A: 

What do you want to trigger the dynamic-resizing? The window being resized? Or the user pressing a button?

If you want to resize text when a user resizes the window, then no - you won't be able to do that with CSS alone, since CSS doesn't have any way of setting font sizes based on the window size. Every site I've seen that does this does it via javascript.

If you want the trigger to be a button press, then this is pretty simple - the button sends a postback to the server, you pick up their desired size from a dropdown or from the specific button that was pressed, and then you can add some CSS into the page or add a link to a different stylesheet.

Chris