|
-
January 30th, 2007, 11:55 AM
#1
Creating HTML to insert at run-time
Forgive me, I'm self-teaching a move to ASP.NET from Windows forms...questions questions...
I want to insert a list, content of which will depend on the user or role. So I think I want to insert some HTML which I'll build in a function somewhere ... but I can't figure out how to get it onto the page in the right place. I want it in one of the divs in my master page. What do I need to put onto the page to allow me to build a string in codebehind (presumably Page_Init) ???
Firstly, does that make sense? Secondly, am I going about this in the right way? Thirdly, can anyone nudge me in the right direction - I'm sure it's an "easy when you know how" moment...
Cheers!
-
January 30th, 2007, 12:32 PM
#2
Re: Creating HTML to insert at run-time
I would think that you could use Response.write to post some javascript that might work...
Code:
<SCRIPT LANGUAGE="JavaScript">
<--
document.getElementById("swappable").innerHTML="Good evening";
//-->
</SCRIPT>
I found this code on this website
-
January 30th, 2007, 12:56 PM
#3
Re: Creating HTML to insert at run-time
response write will suffice however its important to note that anythign written via Response.Write will appear in the very top of your page. And that can produce undesired results.
Your best bet is to create a user Control. Inside this user control you just build the html you want and add codebehind on its load event to determine WHAT it should build. This can use the HttpWriter class to write your necessary html in your control. Then you can manually place that control wherever you want in your page.
So your steps would be.
1. Create .ascx file .
2. Write necessary logic codebehind in .ascx file to prepare html using HttpWriter (or another Writer Class)
3. Maybe you want an xml file with standard html you will be using to generate your control
4. you place the control at the position (or div) of the main page you want.
5. when a user logs in the control logic will dictate what should be rendered in the control and it will display on the page.
hth,
mcm
rate my posts!
mcm
-
January 31st, 2007, 07:31 AM
#4
Re: Creating HTML to insert at run-time
I follow you. Seems a trifle complicated for something I would have thought would be run-of-the-mill but I appreciate the assistance
I'll let you know how I go!
Thanks again gurus,
T
-
January 31st, 2007, 10:54 AM
#5
Re: Creating HTML to insert at run-time
everything that seems simple is complicated...sometimes.
mcm
rate my posts!
mcm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|