When the user clicks a radio button it creates a postback where I add a button control dynamically. My problem is I cannot get the dynamically added button to work with on an click event. The button was created in code behind page. - Public Sub rosterAddControls()
-
Dim myBtn As New Button()
-
myBtn.Style.Item("z-index") = "100"
-
myBtn.Style.Item("position") = "absolute"
-
myBtn.Style.Item("top") = (x - 30) & "px"
-
myBtn.Style.Item("left") = y & "px"
-
myBtn.ID = "myBtn"
-
myBtn.Text = "Button 8974"
-
myBtn.OnClientClick = "myBtn_Click()"
-
PlaceHolder1.Controls.Add(myBtn)
-
End Sub
This above code works fine and the button myBtn is displayed when above method is called.
From the help forms that I have read, I gathered I needed to make an AddHandler statement in the Page_Init as shown below. - Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
-
AddHandler myBtn.Click, AddressOf myBtn_Click
-
End Sub
Lastly, I have created a method that should be called when myBtn is clicked. But the below method is never called. - Protected Sub myBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
Dim test As String
-
test = "this is a test "
-
End Sub
Can someone please help me get the dynamically added button myBtn to fire a onClick event.
Thanks
lance
4 1970 Frinavale 9,735
Recognized Expert Moderator Expert
The button has a scope that only exists in this sub. The button is added to the page but that's it.... -
Public Sub rosterAddControls()
-
Dim myBtn As New Button()
-
myBtn.Style.Item("z-index") = "100"
-
myBtn.Style.Item("position") = "absolute"
-
myBtn.Style.Item("top") = (x - 30) & "px"
-
myBtn.Style.Item("left") = y & "px"
-
myBtn.ID = "myBtn"
-
myBtn.Text = "Button 8974"
-
myBtn.OnClientClick = "myBtn_Click()"
-
PlaceHolder1.Controls.Add(myBtn)
-
End Sub
What you need to do is declare the button outside of this sub. Also, you need to declare it "WithEvents " or else no events will be fired...
eg: -
-
Private WithEvents myBtn As Button
-
-
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
-
rosterAddControls()
-
End Sub
-
-
Public Sub rosterAddControls()
-
myBtn = New Button
-
myBtn.Style.Item("z-index") = "100"
-
myBtn.Style.Item("position") = "absolute"
-
myBtn.Style.Item("top") = (x - 30) & "px"
-
myBtn.Style.Item("left") = y & "px"
-
myBtn.ID = "myBtn"
-
myBtn.Text = "Button 8974"
-
PlaceHolder1.Controls.Add(myBtn)
-
End Sub
-
-
Now your button click event will fire: - Protected Sub myBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles myBtn.Click
-
Dim test As String
-
test = "this is a test "
-
End Sub
Cheers!
-Frinny
Frinavale thanks for your help.
I really appreciate the time you took and the corrected code you shared. I have been trying to solve this problem for about a week.
Thanks for the excellent help.
Frinavale 9,735
Recognized Expert Moderator Expert
Frinavale thanks for your help.
I really appreciate the time you took and the corrected code you shared. I have been trying to solve this problem for about a week.
Thanks for the excellent help.
Glad to have helped!
Cheers!
Again thanks to Frinavale for help on this.
The problem now is being able to save the value of a textbox into a variable I dimed as string "oracleID"
I have added the following code in the Public Sub rosterAddContro ls() txtEditOracle.S tyle.Item("z-index") = "100"
txtEditOracle.S tyle.Item("posi tion") = "absolute"
txtEditOracle.S tyle.Item("Font-Size") = fntSize & "px"
txtEditOracle.S tyle.Item("top" ) = x & "px"
txtEditOracle.S tyle.Item("left ") = y & "px"
txtEditOracle.V isible = showRosterTools
txtEditOracle.W idth = 40
oracleID = txtOracleID.Tex t.ToString Problem is when this sub is called ... Protected Sub myBtn_Click(ByV al sender As Object, ByVal e As System.EventArg s) Handles myBtn.Click
addToDatabase()
End Sub ... the postback calls the page init Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Init
rosterAddContro ls()
End Sub ... this recreates the textbox with no value. If I do not call "rosterAddContr ols()" then the textbox control is not even created.
any help on this would be appreciated.
thanks
lance
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Alex |
last post by:
Hi all,
I'm writing a small web application which searches a database based on
a date field, and populates a datagrid control with the results. The
datagrid control has selection buttons added to it to view additional
details about the selected result (a second database query is
triggered).
I want this second query to pop up in a new window, the way it would
if I used "window.open" in javascript. I've added a function in the
|
by: RA |
last post by:
I have created a button dynamically; which has been added to a TableCell of
a TableRow of a Table control.
Is there a way to add onclick event which calls a procedure on the
Server-side itself.
Any suggestions?
I tried with
btnAdd.Attributes.Add("onClick","AddItem();")
|
by: Dennis Fazekas |
last post by:
Greetings,
I am creating a web form which will all the user to add an unlimited number
of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to
remove, and a "Save" button. When the user clicks the "Add another email" it
will call a client side JavaScript function, add_email, which will
dynamically add a new set of controls to the webpage using the innerHTML
method. It appears to work perfectly fine in the browser. The...
|
by: funkychicken818 |
last post by:
hi i have recently created a JavaScript DOM script and well for some
reason i t does not work.
can you help me find the problem?
here is the script
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
|
by: extremerep |
last post by:
My task is to change the value of a button and then make it functional
with the onClick handler. Changing the value to "Play Again" works, but
making the onClick work accordingly does not. The following is a
snippet of the script. What is keeping it from working?
function displaycards1(){
document.form1.reveal1.value="Play Again";
document.form1.reveal1.onClick="setcards();";
}
</script>
| |
by: |
last post by:
The problem lies here eval("document.TeeForm.amt.value(S+M)");
S and M suppose to add up and the total suppose to appear on the AMT field
but it didn't. Any help?
============================ CODE
==============================================
|
by: Jay |
last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send
text messages to many, many employees via system.timer at a 5 second
interval. Basically, I look in a SQL table (queue) to determine who needs
to receive the text message then send the message to the address. Only
problem is, the employee may receive up to 4 of the same messages because
each thread gets the recors then sends the message. I need somehow to
prevent...
|
by: aljamala |
last post by:
Hi,
I keep getting this warning on a page, but I do not know what the
problem is...does anyone have an idea about what could be wrong?
line 88 column 7 - Warning: missing </formbefore <td>
it highlights this line: <form name="frmCurrency" action=""
method="post">
Page source....
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted
********************************************************
For this teeny job, please refer to:
http://feeds.reddit.com/feed/8fu/?o=25
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |