Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Firing Events of dynamically loaded User Control

Reply
Thread Tools

Firing Events of dynamically loaded User Control

 
 
Raed Sawalha
Guest
Posts: n/a
 
      10-07-2004
I am trying to sort a DataGrid in a user control that is programatically
loaded when a link button is clicked.
UC1 is loaded onto Page1.aspx after clicking a link button. No problem,
loads fine.
How do I call the following event on UC1 when the sort collumn of the data
grid is clicked?

Sub DataGrid1_SortCommand(ByVal s As Object, ByVal e As
DataGridSortCommandEventArgs)

When I click on the sort collumn, the Page_Load event of Page1.aspx is
called, not the above Sub. If I load this user control at design time it
works ok, just not when it it is loaded programatically.

Can I check for e in the Page1.aspx Page_Load event?
If Not Page.IsPostBack then
'Do Something
Else
If e = something then
Call the Sub DataGrid1_SortCommand(...)
End If
End If
Is this correct or is there a better way to be doing this?

thanks,



 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      10-07-2004
The reason the sub isn't firing is because UC1 no longer exists...you need
to reload it on postback. Typically the way this has been done is to store
which dynamic controls have been loaded into the viewstate then reload them
on postback ala:

sub page_load
if page.ispostback then
dim controlPath as string= cstr(ViewState("lastControl"))
if not controlPath is nothing then
dim c as control = Page.LoadControl(controlPath )
Page.COntrols.Add(c)
end if
end if
end sub

sub linkbutton_click
dim c as control = Page.LoadControl("uc1.ascx")
Page.Controls.Add(c)
ViewState.Add("lastControl", "uc1.ascx")
end sub


Alternatively, you can use Denis Bauer's dynamic placeholder which does
this for you (though i've never used it)
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/


"Raed Sawalha" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am trying to sort a DataGrid in a user control that is programatically
> loaded when a link button is clicked.
> UC1 is loaded onto Page1.aspx after clicking a link button. No problem,
> loads fine.
> How do I call the following event on UC1 when the sort collumn of the data
> grid is clicked?
>
> Sub DataGrid1_SortCommand(ByVal s As Object, ByVal e As
> DataGridSortCommandEventArgs)
>
> When I click on the sort collumn, the Page_Load event of Page1.aspx is
> called, not the above Sub. If I load this user control at design time it
> works ok, just not when it it is loaded programatically.
>
> Can I check for e in the Page1.aspx Page_Load event?
> If Not Page.IsPostBack then
> 'Do Something
> Else
> If e = something then
> Call the Sub DataGrid1_SortCommand(...)
> End If
> End If
> Is this correct or is there a better way to be doing this?
>
> thanks,
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
dynamically adding controls with events (but events are not firing) SevDer ASP .Net 2 11-13-2007 06:33 AM
click events no longer work on dynamically loaded web user control =?Utf-8?B?Smlt?= ASP .Net 2 08-20-2007 03:32 AM
Help: Control lost doesn't raise event after being moved to dynamically loaded user control Thanh Nguyen ASP .Net 0 04-01-2004 02:23 AM
Dynamically loaded user control events not firing on first click Earl Teigrob ASP .Net 1 02-10-2004 03:10 PM
Events in dynamically loaded user controls Danny Bloodworth ASP .Net 2 11-21-2003 07:23 AM



Advertisments