Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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!
  #2 (permalink)  
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/
  #3 (permalink)  
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.
  #4 (permalink)  
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/
  #5 (permalink)  
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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:03 PM.


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