Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 October 13th, 2005, 08:02 AM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using rendercontrol with parameters?

hi there.

I am rendering controls using their path information then outputting the HTML. Something like...

Code:
StringBuilder sb = new StringBuilder();
HtmlTextWriter textWriter = new HtmlTextWriter(new StringWriter(sb));
UserControl objControl = (UserControl) LoadControl( inControlPath );

if (objControl != null)
      objControl.RenderControl(textWriter);

return sb.ToString();
Now my problem is that in order to render a specific control the way I want to, I either need to call a specific function within the control or set a property on the control or pass a parameter to it...?

Does anyone have an idea how I can do this?

Appreciate it...


 
Old October 13th, 2005, 08:54 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi shenku,

Instead of casting it to a generic UserControl, cast the results from LoadControl to your type. Then you can set the property you want:
Code:
MyCoolControl objControl = (MyCoolControl) LoadControl( inControlPath );
objControl.SomeProperty = someValue;
Does this help,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old October 13th, 2005, 09:21 AM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Shot.

That has pretty much worked. I couldnt use a property so just using a normal method. Instead of using the type of control (because its all dynamic) I used standard control and reflection to run the function.

Nice.






Similar Threads
Thread Thread Starter Forum Replies Last Post
using Page.RenderControl() net_hunk .NET Framework 2.0 2 May 26th, 2014 04:26 AM
Parameters dcct84 C# 6 September 27th, 2007 05:26 PM
RenderControl and Render methods joxa83 ASP.NET 1.x and 2.0 Application Design 4 August 24th, 2006 08:10 AM





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