0

I am trying to print out HTML to an area of my site based on the selection of a drop down box on the page.

I know I can add Response.Write("My HTML"); in the aspx file where I want the output to be but this needs to be done from the DropDown_SelectedIndexChanged event. This event should query some data in a database then output some information to the page for the user but obviously when using Response.Write in this event handler it will just print to the top of the page.

How can I output HTML code to an area of the webpage from this event, can the function be somehow moved to the ASPX code so it get outputted in the correct place.

Thanks for your help

3 Answers 3

2

just put this on your aspx page:

<asp:Literal id="lc_MyContent" runat="server" />

And then in your code behind use this code to set it from your event:

lc_MyContent.Text =  "<b><u>Hello world!</b></u>";
Sign up to request clarification or add additional context in comments.

Comments

2

You should use the Literal control instead of the Label control because the Label control renders the HTML inside span tags which shouldn't contain block level elements. Literal just renders your HTML and nothing else.

Comments

1

Put a Label control where you want the output to be placed. Give this Label control an ID of lblOutput, say.

Then in your code you would do:

lblOutput.Text = "The stuff you want to appear in that position"

1 Comment

Thanks so much, so obvious now feel a bit stupid now. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.