Ask a Question related to ASP.NET General, Design and Development.
-
Jeffrey A. Voigt #1
Help w/AddHandler (Not Firing Off)
Can someone take a quick glace at my code and tell me why my
AutoPostBackHandler function does not get fired off at all? What I'm trying
to do is get all of the Buttons and DropDownList controls that have an
AutoPostBack property set to true to fire off the AutoPostBackHandler
function dynamically. I achive this by going through all controls that are
on the WebPage and seting up the handler on the fly. I've debugged this and
know for a fact that the AddHandler's are in fact being called with no
errors. The problem is though when the user clicks on a button and/or
change the index of the dropdown (and when page is posted back to the
server) The AutoPostBackHandler is NOT being triggered.
Is there something I'm doing wrong?
Thanks,
- Jeff
************************************************** ******************
************************************************** ******************
************************************************** ******************
Imports System.Text
Imports System.Reflection
Public Class BaseWebPage
Inherits Page
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' if this is a post back then get out
If Page.IsPostBack Then Return
' go through all controls and setup an auto post back handler
' for all controls that have their auto post back property set to
true
RegisterAutoPostBackHandlers(Page)
End Sub
Private Sub RegisterAutoPostBackHandlers(ByRef c As Control)
' get the type name of the control
Dim typeName As String = c.GetType().Name
' only register autopost back event handlers for the following
controls
Select Case typeName
Case "Button"
' cast to button
Dim b As Button = CType(c, Button)
' buttons always post back to add the handler
AddHandler b.Click, AddressOf AutoPostBackHandler
Case "DropDownList"
' cast to a drop down list
Dim ddl As DropDownList = CType(c, DropDownList)
' register the handler if the autopostback is set to true
If ddl.AutoPostBack Then
AddHandler ddl.SelectedIndexChanged, AddressOf
AutoPostBackHandler
End If
End Select
' return if the control has no children
If Not c.HasControls Then Return
' recurse through children
Dim i As Integer
For i = 0 To c.Controls.Count - 1
RegisterAutoPostBackHandlers(c.Controls(i))
Next
End Sub
' handler for all controls that just auto posted back
Public Sub AutoPostBackHandler(ByVal sender As Object, ByVal e As
System.EventArgs)
' register startup script to navigate back to the button
RegisterStartupScript("ScrollBack", "<script>document.forms[0]." +
sender.GetType().Name + ".ScrollTo();</script>")
End Sub
End Class
************************************************** ******************
************************************************** ******************
************************************************** ******************
Jeffrey A. Voigt Guest
-
PageIndexChanged Not Firing
Bingo! that did the trick. Thanks for your help "Elton Wang" wrote: > Check if your datagrid's enableviewstate is false. Set it to true or when... -
AddHandler statement
I created a DataGrid dynamically using a PlaceHolder; to sort the DataGrid I used the AddHandler statement ( AddHandler myDataGrid.SortCommand,... -
Problem using AddHandler for dynamically created WebControls
I am using the AddHandler statement to add a CheckedChanged event handler to a series of RadioButtons that I create in a loop. However, the handler... -
Custom web control - Unable to capture events with AddHandler in an ITemplate
Ok, I know this has been asked a lot. And I see a lot on the topic, but things are a little different here and it's still not quite working for... -
Session_End Not Firing
Hey guys I have a user tracking setup to track users. What it does is once a user hits my site it sends me an email telling me some info and once a... -
MS News \(MS ILM\) #2
Re: Help w/AddHandler (Not Firing Off)
Handle each postback indvidually why you are lumping them together?
"Jeffrey A. Voigt" <jvelite@earthlink.net> wrote in message
news:u8Kvl%230XDHA.1384@TK2MSFTNGP10.phx.gbl...trying> Can someone take a quick glace at my code and tell me why my
> AutoPostBackHandler function does not get fired off at all? What I'mare> to do is get all of the Buttons and DropDownList controls that have an
> AutoPostBack property set to true to fire off the AutoPostBackHandler
> function dynamically. I achive this by going through all controls thatand> on the WebPage and seting up the handler on the fly. I've debugged this> know for a fact that the AddHandler's are in fact being called with no
> errors. The problem is though when the user clicks on a button and/or
> change the index of the dropdown (and when page is posted back to the
> server) The AutoPostBackHandler is NOT being triggered.
>
> Is there something I'm doing wrong?
>
> Thanks,
> - Jeff
>
> ************************************************** ******************
>
> ************************************************** ******************
>
> ************************************************** ******************
>
>
>
> Imports System.Text
>
> Imports System.Reflection
>
>
>
> Public Class BaseWebPage
>
> Inherits Page
>
>
>
> Private Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>
> ' if this is a post back then get out
>
> If Page.IsPostBack Then Return
>
>
>
> ' go through all controls and setup an auto post back handler
>
> ' for all controls that have their auto post back property set to
> true
>
> RegisterAutoPostBackHandlers(Page)
>
> End Sub
>
>
>
> Private Sub RegisterAutoPostBackHandlers(ByRef c As Control)
>
> ' get the type name of the control
>
> Dim typeName As String = c.GetType().Name
>
>
>
> ' only register autopost back event handlers for the following
> controls
>
> Select Case typeName
>
>
>
> Case "Button"
>
> ' cast to button
>
> Dim b As Button = CType(c, Button)
>
> ' buttons always post back to add the handler
>
> AddHandler b.Click, AddressOf AutoPostBackHandler
>
>
>
> Case "DropDownList"
>
> ' cast to a drop down list
>
> Dim ddl As DropDownList = CType(c, DropDownList)
>
> ' register the handler if the autopostback is set to true
>
> If ddl.AutoPostBack Then
>
> AddHandler ddl.SelectedIndexChanged, AddressOf
> AutoPostBackHandler
>
> End If
>
>
>
> End Select
>
>
>
> ' return if the control has no children
>
> If Not c.HasControls Then Return
>
>
>
> ' recurse through children
>
> Dim i As Integer
>
> For i = 0 To c.Controls.Count - 1
>
> RegisterAutoPostBackHandlers(c.Controls(i))
>
> Next
>
> End Sub
>
>
>
> ' handler for all controls that just auto posted back
>
> Public Sub AutoPostBackHandler(ByVal sender As Object, ByVal e As
> System.EventArgs)
>
> ' register startup script to navigate back to the button
>
> RegisterStartupScript("ScrollBack", "<script>document.forms[0]." +
> sender.GetType().Name + ".ScrollTo();</script>")
>
> End Sub
>
>
>
> End Class
>
>
>
> ************************************************** ******************
>
> ************************************************** ******************
>
> ************************************************** ******************
>
>
MS News \(MS ILM\) Guest
-
Jeffrey A. Voigt #3
Re: Help w/AddHandler (Not Firing Off)
I do handle each post back seperately, but i'm also creating a dynamic
handler for some auto scrolling on each postback. I'm doing this in a base
class so that all webpages get this effect. Now can someone help me answer
my initial question instead of asking one instead? :)
Thanks,
- Jeff
"MS News (MS ILM)" <sql_agentman@hotmail.com> wrote in message
news:e4dKp63XDHA.652@TK2MSFTNGP10.phx.gbl...to> Handle each postback indvidually why you are lumping them together?
>
>
> "Jeffrey A. Voigt" <jvelite@earthlink.net> wrote in message
> news:u8Kvl%230XDHA.1384@TK2MSFTNGP10.phx.gbl...> trying> > Can someone take a quick glace at my code and tell me why my
> > AutoPostBackHandler function does not get fired off at all? What I'm> are> > to do is get all of the Buttons and DropDownList controls that have an
> > AutoPostBack property set to true to fire off the AutoPostBackHandler
> > function dynamically. I achive this by going through all controls that> and> > on the WebPage and seting up the handler on the fly. I've debugged this> > know for a fact that the AddHandler's are in fact being called with no
> > errors. The problem is though when the user clicks on a button and/or
> > change the index of the dropdown (and when page is posted back to the
> > server) The AutoPostBackHandler is NOT being triggered.
> >
> > Is there something I'm doing wrong?
> >
> > Thanks,
> > - Jeff
> >
> > ************************************************** ******************
> >
> > ************************************************** ******************
> >
> > ************************************************** ******************
> >
> >
> >
> > Imports System.Text
> >
> > Imports System.Reflection
> >
> >
> >
> > Public Class BaseWebPage
> >
> > Inherits Page
> >
> >
> >
> > Private Sub Page_Load(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> >
> > ' if this is a post back then get out
> >
> > If Page.IsPostBack Then Return
> >
> >
> >
> > ' go through all controls and setup an auto post back handler
> >
> > ' for all controls that have their auto post back property settrue> > true
> >
> > RegisterAutoPostBackHandlers(Page)
> >
> > End Sub
> >
> >
> >
> > Private Sub RegisterAutoPostBackHandlers(ByRef c As Control)
> >
> > ' get the type name of the control
> >
> > Dim typeName As String = c.GetType().Name
> >
> >
> >
> > ' only register autopost back event handlers for the following
> > controls
> >
> > Select Case typeName
> >
> >
> >
> > Case "Button"
> >
> > ' cast to button
> >
> > Dim b As Button = CType(c, Button)
> >
> > ' buttons always post back to add the handler
> >
> > AddHandler b.Click, AddressOf AutoPostBackHandler
> >
> >
> >
> > Case "DropDownList"
> >
> > ' cast to a drop down list
> >
> > Dim ddl As DropDownList = CType(c, DropDownList)
> >
> > ' register the handler if the autopostback is set to+> >
> > If ddl.AutoPostBack Then
> >
> > AddHandler ddl.SelectedIndexChanged, AddressOf
> > AutoPostBackHandler
> >
> > End If
> >
> >
> >
> > End Select
> >
> >
> >
> > ' return if the control has no children
> >
> > If Not c.HasControls Then Return
> >
> >
> >
> > ' recurse through children
> >
> > Dim i As Integer
> >
> > For i = 0 To c.Controls.Count - 1
> >
> > RegisterAutoPostBackHandlers(c.Controls(i))
> >
> > Next
> >
> > End Sub
> >
> >
> >
> > ' handler for all controls that just auto posted back
> >
> > Public Sub AutoPostBackHandler(ByVal sender As Object, ByVal e As
> > System.EventArgs)
> >
> > ' register startup script to navigate back to the button
> >
> > RegisterStartupScript("ScrollBack", "<script>document.forms[0].">> > sender.GetType().Name + ".ScrollTo();</script>")
> >
> > End Sub
> >
> >
> >
> > End Class
> >
> >
> >
> > ************************************************** ******************
> >
> > ************************************************** ******************
> >
> > ************************************************** ******************
> >
> >
>
Jeffrey A. Voigt Guest
-
Natty Gur #4
Re: Help w/AddHandler (Not Firing Off)
Jeffrey Hi,
I dont see any problem. I run this code which is basicly yours and it
works.
Private Sub ddo(ByRef tar As Control)
Dim control As Control
For Each control In tar.Controls
Select Case control.GetType().Name
Case "Button"
AddHandler CType(control, Button).Click, AddressOf
Natty
Case "ListBox"
AddHandler CType(control,
ListBox).SelectedIndexChanged, AddressOf Natty
End Select
If tar.Controls.Count > 0 Then
ddo(control)
End If
Next
End Sub
Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Natty Gur Guest
-
Natty Gur #5
Re: Help w/AddHandler (Not Firing Off)
Jeff hi,
yes, firing off whenever there is a postback caused by those
controls.
Try to create new project and run it with the code. Maybe something in
the application causes the miss behavior.
Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Natty Gur Guest
-
Jeff Voigt #6
Re: Help w/AddHandler (Not Firing Off)
is your code that set's up the events ran every time there is a post back?
"Natty Gur" <natty@dao2com.com> wrote in message
news:emMpMiBYDHA.2152@TK2MSFTNGP09.phx.gbl...> Jeff hi,
>
> yes, firing off whenever there is a postback caused by those
> controls.
>
> Try to create new project and run it with the code. Maybe something in
> the application causes the miss behavior.
>
> Natty Gur, CTO
> Dao2Com Ltd.
> 34th Elkalay st. Raanana
> Israel , 43000
> Phone Numbers:
> Office: +972-(0)9-7740261
> Fax: +972-(0)9-7740261
> Mobile: +972-(0)58-888377
>
>
> *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
> Don't just participate in USENET...get rewarded for it!
Jeff Voigt Guest



Reply With Quote

