And
quick to render HTML content at this point were just slamming out the text of
this control will lets you use this control on the page go to add it to my
solution a website that's fine that's fine that's fine limit rebuild everything
by rebuilding everything I allow Visual Studio to play a fun trip and that is
here in design view in the toolbox window once I've built my solution Visual
Studio season has this server control available for use on this page it looks
like a server control.
So they supply it as an
option on the toolbox window I could drag this onto the page and because right
now my server control has no text property it displays its ID property in
square brackets the class they the server control one as the first instance of
that control so as a server control one number one and if I come your change
the text to the obligatory hello world the control updates to display that text
will lets you run this page and see what's really going output when ASP.net
renders the page with ASP.net renders this page we see in the browser for look
at the source here a span tag.
Which
contains our control and here's hello world actually the span tag is how
ASP.net represents a label is treating this like a label control well that's
good enough we see that they've managed to spit out the HTML is required for
this control what if I want to say a few have some I can come to my control and
here in the override for the render contents method I just need to spit out
some more HTML so I need to come out here and add a call to output.adding some
way to write out the beginning of the span tag is a right for all begin tag
methods courses also a right begin tag method which rights the opening tag with
room to put attributes so the right begin tag won't put the closing bracket
write full begin tag closes the opening tag of our span element.
So
I need here to figure how I put the span out this needs to be a strain I could
just type the word span about 12 I will use HTML text writer tag is I love this
because they give us enumeration which is all of the possible HTML elements I
want span.2 strings there we go that's the begin tag at the end money the output.
Right and tag HTML text writer tag.span.to string there we go save this go back
to our page this rebuild everything I was view the page the browser and see
what happens it looks the same if we look at the source you see that what we
spit out now is a little more complicated the contents of our external span
contains an internal span with the text property of our custom control in there
so we've created a custom control and modify the HTML.
thank you it is hard work
ReplyDelete