PC Review


Reply
Thread Tools Rate Thread

Addding usercontrol dynmaically with postback capability

 
 
news.microsoft.com
Guest
Posts: n/a
 
      26th Apr 2010
Hello,

I am trying to add an asp.net user control dynamically with the postback
capability.

Adding a user control seems straightfroward but making postback work is a
problem. When I say postback, I mean postback handled inside the
usercontrol.
e.g. let's say your user control has a text and a button. You save the text
property in viewstate varible so that it is preserved during postback. You
assign the new property value from textbox to viewstate variable after
postback.

Problem comes when controls are created dynamically.

Any help will be appreciated to make this work.

regards,
Pravin


 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      26th Apr 2010
What event do you dynamically add the user control? The main issue, the user
control must maintain the same id from postback to postback. If you add it
too late, it actually gets added after the postback event so none of the
click event gets fired. You have to add the control early. What I usually do
is add the control in the OnLoad or OnPreLoad event. Then if something
changes where I have to swap the control, I do it in the OnPreRender event
after wiping out the previously added control.

Another key issue, the id. Controlling the ID of the dynamically added
control will help you maintain consistancy in the postback events.

Hope this helps,
Mark Fitzpatrick

"news.microsoft.com" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I am trying to add an asp.net user control dynamically with the postback
> capability.
>
> Adding a user control seems straightfroward but making postback work is a
> problem. When I say postback, I mean postback handled inside the
> usercontrol.
> e.g. let's say your user control has a text and a button. You save the
> text property in viewstate varible so that it is preserved during
> postback. You assign the new property value from textbox to viewstate
> variable after postback.
>
> Problem comes when controls are created dynamically.
>
> Any help will be appreciated to make this work.
>
> regards,
> Pravin
>

 
Reply With Quote
 
Cubaman
Guest
Posts: n/a
 
      27th Apr 2010
On Apr 26, 5:52*pm, "news.microsoft.com" <sable_pra...@emc.com> wrote:
> Hello,
>
> I am trying to add an asp.net user control dynamically with the postback
> capability.
>

Take a look at this user control, it might help you:
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

Best regards

> Adding a user control seems straightfroward but making postback work is a
> problem. When I say postback, I mean postback handled inside the
> usercontrol.
> e.g. let's say your user control has a text and a button. You save the text
> property in viewstate varible so that it is preserved during postback. *You
> assign the new property value from textbox to viewstate variable after
> postback.
>
> Problem comes when controls are created dynamically.
>
> Any help will be appreciated to make this work.
>
> regards,
> Pravin


 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      28th Apr 2010


"news.microsoft.com" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I am trying to add an asp.net user control dynamically with the postback
> capability.
>
> Adding a user control seems straightfroward but making postback work is a
> problem. When I say postback, I mean postback handled inside the
> usercontrol.
> e.g. let's say your user control has a text and a button. You save the
> text property in viewstate varible so that it is preserved during
> postback. You assign the new property value from textbox to viewstate
> variable after postback.
>
> Problem comes when controls are created dynamically.
>
> Any help will be appreciated to make this work.


Mark has hit this on the head. In order to work with viewstate, you have to
have the control on the page prior to when viewstate is applied back, which
means before the Load event. Take a look at the page lifecycle events and
you will understand why adding the control on load completely messes up your
system.

--
Peace and Grace,
Greg

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

************************************************
| Think outside the box! |
************************************************

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
UserControl and Postback supvine@gmail.com Microsoft ASP .NET 3 13th Mar 2006 11:50 PM
Postback from a cached usercontrol? Rick Microsoft ASP .NET 0 6th Feb 2006 04:49 AM
Disable Usercontrol resize capability =?Utf-8?B?amFtbWluYw==?= Microsoft Dot NET Framework Forms 0 28th Jun 2005 09:58 AM
Re-loading a UserControl after PostBack jon Microsoft ASP .NET 2 29th Apr 2005 01:25 PM
PostBack + usercontrol Dan Microsoft ASP .NET 4 1st May 2004 06:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:47 AM.