Good morning,
Still new at this so please bear with me. I am creating a table dynamically
using webcontrols based on the output of a sproc from my database.The table
represents test instances that the test proctor who is viewing the page has
currently assigned to him or heir. Each row of the table corresponds to a
single test instance and includes required info about that test.
At the end of the row I create a button control. Based on whether or not the
test is currently active, this button will either allow the user to activate
the test or change the test date.
This all works fine, up to the point of using the AddHandler. Here is the
button code:
dim newBtn as new Button()
'Text, class assignment, etc.
if bIsActive = true then
AddHandler newBtn.Click, AddressOf change_test_dat e
else
AddHandler newBtn.Click, AddressOf activate_test
end if
So ok, this works, except I have to pass the test number with this event to
make sure the correct test is addressed and updated. I tried
AddHandler newBtn.Click, AddressOf change_test_dat e(objReader("te st_num"))
But I get the following error:
'AddressOf' operand must be the name of a method; no parentheses are needed.
The question is how do I pass the test number as an argument for this event?
I am sure its something simple, but I can't find it. Any help would be really
appreciated. Thanks in advance.
Jim Hawley 4 2365
I take part of it back, the AddHandler throws errors, but when I use just
plain
AddHandler newBtn.Click, AddressOf change_test_dat e
and have the following sub:
sub change_test_dat e(Sender as Object, e as EventArgs)
'Whatever
end sub
and execute the page and then check the source, there is no onclick event
for the button. Yet if I do like referenced below, I get an error. Go
figure...help!
Jim Hawley
"DJ" wrote: Good morning,
Still new at this so please bear with me. I am creating a table dynamically using webcontrols based on the output of a sproc from my database.The table represents test instances that the test proctor who is viewing the page has currently assigned to him or heir. Each row of the table corresponds to a single test instance and includes required info about that test.
At the end of the row I create a button control. Based on whether or not the test is currently active, this button will either allow the user to activate the test or change the test date.
This all works fine, up to the point of using the AddHandler. Here is the button code:
dim newBtn as new Button() 'Text, class assignment, etc. if bIsActive = true then AddHandler newBtn.Click, AddressOf change_test_dat e else AddHandler newBtn.Click, AddressOf activate_test end if
So ok, this works, except I have to pass the test number with this event to make sure the correct test is addressed and updated. I tried
AddHandler newBtn.Click, AddressOf change_test_dat e(objReader("te st_num"))
But I get the following error:
'AddressOf' operand must be the name of a method; no parentheses are needed.
The question is how do I pass the test number as an argument for this event? I am sure its something simple, but I can't find it. Any help would be really appreciated. Thanks in advance.
Jim Hawley
DJ wrote: I take part of it back, the AddHandler throws errors, but when I use just plain
AddHandler newBtn.Click, AddressOf change_test_dat e
and have the following sub:
sub change_test_dat e(Sender as Object, e as EventArgs) 'Whatever end sub
and execute the page and then check the source, there is no onclick event for the button. Yet if I do like referenced below, I get an error. Go figure...help!
Jim Hawley
If "test_num" is a simple integer, then when you assign your Button an ID,
you could append the test_num to the end of the ID. Something like:
newBtn.ID = "btn" & objReader("test _num")
Then in your event handler, you can get the test_num value by checking the
ID of the 'Sender' parameter.
Another option is to store the test_num value and the Button's ID in
ViewState:
ViewState(newBt n.ID) = objReader("test _num")
Then when your event handler is called, you can extract the test_num value
out of ViewState using the ID of the 'Sender' parameter.
Good luck,
Ben
Sounds good but I can't get the event handler to fire. I checked the source
and its not there. I did code the IDs of the buttons like you said before
hand so I wouldn't get the error where two or more objects have the same ID,
so I could use it if I could just get the event handler to fire.
I even thought about doing it as follows:
sub Page_Load(Sende r as Object, e as EventArgs)
dim sTempText as string
If IsPostBack then
sTempText = Sender.ID
end if
end sub
but all I get back there is ASP.pagename.
I've put just a label.Text = "hi there" in the event handler to show that
its firing and nothing.
Any ideas? I think my base is that the AddHandler is not functioning.
Jim
"Ben Amada" wrote: DJ wrote:
I take part of it back, the AddHandler throws errors, but when I use just plain
AddHandler newBtn.Click, AddressOf change_test_dat e
and have the following sub:
sub change_test_dat e(Sender as Object, e as EventArgs) 'Whatever end sub
and execute the page and then check the source, there is no onclick event for the button. Yet if I do like referenced below, I get an error. Go figure...help!
Jim Hawley
If "test_num" is a simple integer, then when you assign your Button an ID, you could append the test_num to the end of the ID. Something like:
newBtn.ID = "btn" & objReader("test _num")
Then in your event handler, you can get the test_num value by checking the ID of the 'Sender' parameter.
Another option is to store the test_num value and the Button's ID in ViewState:
ViewState(newBt n.ID) = objReader("test _num")
Then when your event handler is called, you can extract the test_num value out of ViewState using the ID of the 'Sender' parameter.
Good luck, Ben
I created a small example which demonstates what you're trying to do and it
appears to work on my end. Also, you shouldn't have to worry about a
missing "onclick" attribute where the button is defined in the rendered
HTML. I'm fairly certain the reason for this is because ASP.NET stores the
button's click event to your event handler in ViewState. Below is the
rendered HTML I see for a dynamically created button which has an event
handler tied to it:
<input type="submit" name="btn1" value="Button 1" id="btn1" />
Below is the code I used. You might want to compare what you have to the
code below or try the code below and see what happens on your end.
Private Sub Page_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
Dim newBtn As Button
For i As Integer = 1 To 5
newBtn = New Button
newBtn.ID = "btn" & i.ToString
newBtn.Text = "Button " & i.ToString
PlaceHolder1.Co ntrols.Add(newB tn)
AddHandler newBtn.Click, AddressOf MyButtonHandler
Next
End Sub
Private Sub MyButtonHandler ( _
ByVal sender As System.Object, _
ByVal e As System.EventArg s)
Dim sID As String
sID = CType(sender, Button).ID.Subs tring(3)
End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Supra |
last post by:
how do i do get menuitem "Connect" in addhandler ?
Private Sub mnuIrc_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuIrcConnect.Click, mnuIrcPref.Click,
mnuIrcExit.Click
Dim mi As MenuItem = CType(sender, MenuItem)
Select Case mi.Text
Case "Connect"
Dim p As Integer = 6667
|
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 that have an
AutoPostBack property set to true to fire off the AutoPostBackHandler
function dynamically. I achive this by going through all controls...
|
by: Nathan Sokalski |
last post by:
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 is
not being called for a reason I cannot determine. What is the problem? Here
is my code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load...
|
by: Luis Esteban Valencia Muñoz |
last post by:
Have a dropdownlist created in my LoadMain() which is called from the
Page_load:
************************PAGE LOAD********************8Private Sub
Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Try
'Initialize.
Main.SetBodyURL(Page)
conSess = MySession.Connection(Session)
objPP =...
|
by: Just Me |
last post by:
When a document is to be printed I call a method that contains an AddHandler
statement.
I just realized that if a second copy is to be printed the method is called
and the AddHandler is executed again.
Is doing AddHandler a second time wrong?
I did check and even though I do AddHandler 3 times the handler is only
called once.
| |
by: Carlo3030 |
last post by:
Been reading Dino Esposito's Article "A DetailsView Control for ASP.NET 1.x"
found in the msdn Library. His example was created using VB.NET. I am trying
to convert the example (DetailsView control) to C#.
The Issue is I converted this line (in VB):
AddHandler _insertButton.Click, AddressOf OnApplyInsertMode
to C#.NET with this:
|
by: Slim |
last post by:
i have a simple page, with one button button1.
when click it creates a new button button 2 and adds a event handler to it.
but when button 2 is clicked nothing happens, why?
Partial Class test_buttons
Inherits System.Web.UI.Page
Dim bt2 As Button
|
by: ugavnholt |
last post by:
Hi All,
I'm having a problem with a small bit of code:
Dim deleteButton = New System.Web.UI.WebControls.ImageButton
deleteButton.imageURL = "images/icondelete.gif"
deleteButton.ToolTip = "Delete Data Source"
deleteButton.CommandArgument = "Delete1"
AddHandler deleteButton.Click, AddressOf DeleteDataSource_Click
|
by: Nathan Sokalski |
last post by:
I have a section of my code that dynamically creates LinkButtons to allow
the user to go to the page containing a question they have not answered. The
code that creates the LinkButton is called, as well as the AddHandler line
(I ran a Debug and saw that it executes this code, and the links are
displayed on the page afterwards). However, the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |