I use Asp.net 4 and C#.
I have a common web control <asp:Panel>. It is my understanding that if the Panel is visible it renders in the Browser as a <div></div> tag.
I would like to know if is possible to change this behavior and display the content of the Panel without rendering its <div>.
Any idea how to do it?
Can I use another control instead of Panel?
An example of code would be appreciated thanks!
Simple :
use PlaceHolder or Literal
it renders only what it has - nothing more nothing less.
If you use an ASP.NET PlaceHolder control then you will not get the div tags.
Of course if you use a PlaceHolder you will not get a HTML element for this (i.e. a DIV tag) so you cannot set properties such as BackImageUrl or Wrap, etc. on the control.
Related
I'm building a kind of simple In-Application CMS and I'm gonno let the user to upload an HTML and a CMS file as Masterpage.
A solution I thought was asking user to put some Pre-Defined Tags inside HTML so I can replace them with ContentPlaceHolder control. The reason of replacing ContentPlaceHolder is that I may have some Web Controls and need postback handling so I cannot convert everything to Html and put them to an HTML and push to client.
And the Questions:
1- Is there any better solution?
2- Is it possible? How can I replace some string with CPH Control?
Regards
To my knowledge you cannot dynamically generate content placeholders at runtime. So your actual masterpage will have to have them in place ahead of time.
I think you may be able to achieve what you are after by putting Literal controls before and after each content placeholder. Then you could parse your CMS html to determine which html comes before a placeholder and which comes after. Finally set each Literal's text property to the respective parsed html.
Just wanna ask anyone here knows why when i put a placeholder in my masterpage it became like this
[ PlaceHolder "PlaceHolder1" ]
It supposed to be a blank editable box right? I cant even write anything there.
Help me ya. Thank you.
I think you need ContentPlaceHolder instead of PlaceHolder.
Use the PlaceHolder control as a container to store server controls
that are dynamically added to the Web page. The PlaceHolder control
does not produce any visible output and is used only as a container
for other controls on the Web page.
When ContentPlaceHolder is used to hold content from Content Pages and can only be used on a Master Page
You need to add Content Place Holder rather than placeholder
A placeholder is used to reserve some place for dynamically added controls
It is not a blank editable textbox
If you need a textbox for editing, just drop a simple server side textbox control & set its text mode to multiline inside properties.
W3Schools:ASP.NET Placeholder
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
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.
You could create 3 links:
A 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"];
}
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
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%; }
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.
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.
ASP.NET with C#:
I have a web page which is intended to be a help page. Actually I am using a treeview component, and when someone clicks on a node a label on the page will change text by reading it from text file.
what I want is to put some images in the help so a .txt file will not be suitable. So I may use a .html file instead.
How to read such a .html file and display it in my page? May I replace the label with some thing else or what?
Use ASP.NET Literal control instead. The Literal control is used to display text on a page. The text is programmable.
Note: This control does not let you apply styles to its content!
<asp:Literal />
Use <asp:PlaceHolder runat="server"> - it's a more general purpose way of inserting blocks of content into a page.
Use placeholder or literal asp control, because these controls don't put any html for its self, it just render whats inside.
But for example the normal asp label will render as a span.
I have a select checkbox that has invisible set to false. ASPX looks like this:
<input name="selGR" id="selGR" type="checkbox" checked="checked" visible="false" runat="server" fieldname="GR"/>
The select box is not even rendered in the HTML which explains why JQuery is not finding it. Is there a way around this?
EDIT:
Setting style works! Thanks. I am curious to know if there are any rules the .NET framework follows when rendering controls with visible="false"? For all controls irrespective of whether they are server, custom or html controls, it follows this rule?
Also, any side effects of setting the style instead of setting the property of visible?
you can always set the display property to none. jQuery will be able to find it at that point.
<input type="checkbox" id="selGr" style="display:none" />
For future reference as well. $("#selGr").hide() & $("#selGr").show() basically uses the display property of the element.
I do not believe an 'visible' is an attribute of an element. There is visibility and display that can be set within the style attribute though. For a better understand of the difference between visibility and hidden check this out: http://www.devx.com/tips/Tip/13638
Visible is a asp.net attribute,by setting it to false is to ask sever not to render the control. That is why your check box is not in the html source code.
Chaning html display style property to none is telling the explorer not to display the checkbox, however, it is stilled included in the source code.
Use "style='display: none'" instead of "visible='false'". That way it will still be in the rendered HTML for JQuery to do something with.
it is the option that u can use "Display:None",
but if u use this one,
than ur control will render every time in page and if u see it in Firebug,
u will find ur control there and that thing will not occurs in Visible=false