Forum Moderators: open
<myid:tagname
runat="server"
myfile="three.xml"
showlines="false"
/>
Now I want to achieve something more like this:
<myid:bigbox>
my text my text my text my text
</myid:bigbox>
Are User Controls capable of that? If so, is anyone here willing to show me how?
<myid:tagname
runat="server"
myfile="three.xml"
showlines="false"
innertext="blah blah blah"
/>
And then in the UserControl codebehind you declare:
Public innertext As String
Then on the UserControl front end:
<% Response.Write(innertext) %>
This will have the same affect. Not sure if it's the best way, but it'd work.
What are you trying to do exactly?
I'm trying to find a way to wrap custom tags around HTML content to parse/alter/change that content.
<myid:customreplace>
hello world
<p>hello world</p>
<i>hello world</i>
</myid:customreplace>
One thing I'm trying to do immediately is to hide elements from the menu if the user hasn't logged in. Another is to take a long passage of HTML and turn it into a Flash movie or a graphic image.
I had a thought this weekend: If I can't use a user control, what if my program used output buffering and grabbed the chunk of code to manipulate it before it's sent?
1) grab the output buffer
2) extract the HTML bits using regex [code]/<mytag>.*?</mytag>/[code]
3) do the manipulation on that and replace it
4) then send the results to the client
I'm familiar with output buffering in PHP, but I've never tried it in ASP.NET. can I take an output buffer and apply a replacement to it?
<asp:label runat=server id=lblLabel>My Text</label>
you can then access the text in the codebehind with "lblLabel.Text". You could then process this on the page load to do what ever you want.
Or, create your own control and inherit from the label control and make it do the transformation automatically.
The major difference between the two is that a Literal control does not include all the style-based properties a great. If you have more general styles to apply to ALL the text in the control - use a label.Label has. If you know the specific HTML you want to put in (Paragraph/Bold/etc. tags) - the Literal will probably work
You can programmatically control the text displayed in either control by setting the Text property.
Example:
<asp:Literal id="myText_lit" runat="server" Text="my text<br/><b>my text</b><br/>my text<hr/>my text"/>
Custom User Controls are typically used when you find yourself needing to reuse the same formatting/structure on a page multiple times (and typically other code-behind programming logic that affects the display). It may be overkill if you're just trying to format text. Implementation of this route would be similar however - just create your User Control with a literal control/label control/etc. - fill the text properties as you feel fit; and include the call to it in the parent in both the HTML and code behind (if applicable).
namespace System.Web.UI.WebControls.Custom
{
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public abstract class WidgetLabel : Label
{
///<summary>Implementation here</summary>
}
}