Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
| Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2010, 03:03 PM
Registered User
 
Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing dynamically created content in a literal control

Hi- I have a page that contains database-generated dynamic html content. I use a string builder to create the html for the page based off of a SQL stored procedure. Once the string builder is finished, the string is placed in a literal control's text property for display on the page.

Within the content, there are html checkboxes that have javascript onclick events that add content. Basically, if the checkbox is checked, new html items are visible (a couple dropdowns or textareas).

I have a need to generate an email that contains the page's content, INCLUDING the dynamically generated items. When I view the literal control's text property, I do not see any of the dynamically created content.

Is there any way to get at that content without having to recreate it?

Any ideas appreciated, thanks!
 
Old March 4th, 2010, 03:44 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You need to make sure the dynamically created controls have names. Then you retrieve their values using:
Code:
Request.Form["MyControlName"]
in the postback.
__________________
Joe
http://joe.fawcett.name/
 
Old March 4th, 2010, 04:07 PM
Registered User
 
Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response.

I'm not trying to find each individual dynamically created item by its name; I was hoping to find a way to get to the Literal that is already on the page with the new dynamic html items in its text. Using the Literal.Text was what I was hoping for, but that only contains the original stripped down text without the javascript added items.

Am I going to have to find each of those new items individually by name and get their values? I was hoping there would be a way to capture the dynamically created items without having to do that.

I've already started writing something that will basically recreate the whole string builder, but it seems like there would be an easier way to capture the page's rendered content including dynamic items created by javascript.
 
Old March 4th, 2010, 04:50 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

When you add new stuff to a page using script it only gets added to the in-memory model of the browser, not the actual HTML you see in view-source. Therefore you can't retrieve it using the technique you tried. Dynamic controls are difficult to manage in ASP.NET but it shouldn't be difficult to use a standard naming system on the controls, e.g. a prefix followed by an index and then loop through the form elements testing the names to get at their values.
__________________
Joe
http://joe.fawcett.name/
 
Old March 4th, 2010, 05:09 PM
Registered User
 
Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, thanks a lot Joe. I was just trying to see if there was a super-expedient obvious answer I was missing.

I've found another way to get it done; sometimes clients want it now rather than later, no matter what. It works, but I basically recreated the string using another db trip- not efficient, I know, but it's ready for testing today, which was what they expected.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing dynamically created markup in Response stuart_andrews ASP.NET 3.5 Basics 0 June 16th, 2009 07:23 AM
Literal Control bilal589 ASP.NET 1.0 and 1.1 Basics 5 August 19th, 2006 01:42 PM
Saving Data to DB in dynamically created control ashokkumar ASP.NET 1.0 and 1.1 Basics 2 June 23rd, 2006 01:18 PM
Dynamically created controls katsarosj ASP.NET 1.0 and 1.1 Basics 4 February 4th, 2004 09:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.