473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

************************************************** ******************

************************************************** ******************

************************************************** ******************
Nov 17 '05 #1
0 1088

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jeffrey A. Voigt | last post by:
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...
1
by: Lisa | last post by:
I have a web app that gets a recordset from the database and fills a grid. You can drilldown from this table to a detail table. Because the tables sometimes get huge, and because I have to go...
7
by: Tigger | last post by:
Dear Experts, I am working on ASP.NET. I have got a problem related to the usage of Javascript in ASP.NET. Please help. The story is the following: 1) I am developing an ASP.NET application. I...
22
by: Colin McGuire | last post by:
I apologize for posting yet another scrollbar question. Here is my code. All I want is for a diagonal line to appear from coordinates (0,0) to (width,height) in a usercontrol regardless of whether...
3
by: Thiago Arrais | last post by:
I am writing a VS .NET Addin and I need to create menu items (CommandBarButtons) at run-time. I can do that but the event handlers do not work. They are registered using AddHandler (wich was...
28
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when...
1
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
2
by: momo | last post by:
Hello Guys, I have a bit of a problem, I created a Dll called SecureQueryStringDll.dll and I had the dll put bin folder of my application first and it did not work so I then put it in the bin...
12
by: Tom | last post by:
I use dynamically created controls all the time. I.E. I create the control in code then use AddHandler to add the necessary delegates for processing (like Click, etc). Does one have to call...
2
by: Justin | last post by:
I've never work with creating controls on the fly. Now that I am, I'm uncertain about a particular aspect. Example: I have a static listbox named ListBox1. I use the following routine: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.