Hi,
I'm using ASP.NET. I need help adding new buttons to my web page at run
time on the server side prior to sending to the client.
As the web form is loading, I won't know in advance how many buttons I'll
need or the properties for each until I read a database.
For each new button, I need to assign the text, name ('id' for later
reference), and set the code-behind to handle the events for each.
I hope I'm clear. Could someone suggest some code that will help me please?
Thanks,
Doug 2 1800
you can write like this..keep the loop based on your database data.
for(int i=0; i<10; i++)
{
Button btn = new Button();
btn.ID = "Button" + i.ToString();
btn.Text = "Button" + i.ToString();
btn.CommandName = "Button" + i.ToString();
btn.Click += new EventHandler(bt n_Click);
}
private void btn_Click(objec t sender, EventArgs e)
{
Button btn = (Button)sender;
if(btn.CommandN ame == "")
{
}
}
make sure that you always add these controls irrespective of IsPostBack..you
can put them in page_load.
Av.
"Doug Slocum" <ms**********@r estrack.com> wrote in message
news:uT******** *****@tk2msftng p13.phx.gbl... Hi, I'm using ASP.NET. I need help adding new buttons to my web page at run time on the server side prior to sending to the client. As the web form is loading, I won't know in advance how many buttons I'll need or the properties for each until I read a database. For each new button, I need to assign the text, name ('id' for later reference), and set the code-behind to handle the events for each. I hope I'm clear. Could someone suggest some code that will help me please? Thanks, Doug
Av,
In VB.NET I've tried :
----
Try
Dim i As Integer
For i = 0 To 9
Dim btn As New Button
btn.ID = "button" & i.ToString
btn.Text = "button" & i.ToString
btn.CommandName = "button" & i.ToString
Next
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
-------------------
....This runs without errors but no buttons show in the browser. Also, there
is no btn.Click that I can find.
What could be wrong?
Doug
"avnrao" <av*@newsgroups .com> wrote in message
news:u4******** *****@tk2msftng p13.phx.gbl... you can write like this..keep the loop based on your database data.
for(int i=0; i<10; i++) { Button btn = new Button(); btn.ID = "Button" + i.ToString(); btn.Text = "Button" + i.ToString(); btn.CommandName = "Button" + i.ToString(); btn.Click += new EventHandler(bt n_Click); }
private void btn_Click(objec t sender, EventArgs e) { Button btn = (Button)sender; if(btn.CommandN ame == "") { } }
make sure that you always add these controls irrespective of
IsPostBack..you can put them in page_load.
Av.
"Doug Slocum" <ms**********@r estrack.com> wrote in message news:uT******** *****@tk2msftng p13.phx.gbl... Hi, I'm using ASP.NET. I need help adding new buttons to my web page at run time on the server side prior to sending to the client. As the web form is loading, I won't know in advance how many buttons
I'll need or the properties for each until I read a database. For each new button, I need to assign the text, name ('id' for later reference), and set the code-behind to handle the events for each. I hope I'm clear. Could someone suggest some code that will help me please? Thanks, Doug
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: freddy |
last post by:
I would like to add a to z buttoms at runtime
|
by: Lars Netzel |
last post by:
Hey!
I'm adding a ButtonColumn (Push button) in a datagrid in Runtime. How do I
write the code to add the eventhandler for this buttons Click Event?
Best regards
/Lars
|
by: seanmayhew |
last post by:
I have a form page that that while editing saves the data to an xml doc
before submitting to db. On each page
unload it saves the xmldoc as the user can add multiple items to the
company like product types etc. So for
instance Im adding a fruit company while adding a fruit company I allow
the user to add types of fruit they
carry and display it dynamically using an <asp:table> with image
|
by: Byron Hopp |
last post by:
Anybody have code to add a ToolBar, and its buttons to a MDI Child window.
I have added the Toolbar, and added the buttons, but how do you determine
what the button is going to execute upon the user clicking it. How do you
add this code dynamically?
Byron...
|
by: David S. Zuza |
last post by:
Hey,
I am new to .NET and I would like to index a button control on my form
just like I used to be able to in VB6. In VB6 all I had to do was create one
control and new to something like
cmdButton()
and then I could copy it in the design window and refer to anyone of the
buttons by refencing its index like
| |
by: jon f kaminsky |
last post by:
Hi-
I've seen this problem discussed a jillion times but I cannot seem to
implement any advice that makes it work. I am porting a large project from
VB6 to .NET. The issue is using the combo box bound to a table as a lookup,
drawing values from another table to populate the available selections. This
all worked fine in VB6.
I have distilled the problem down to a simple form drawing data from the
Northwind database for a representative...
|
by: Learner |
last post by:
Hello,
I have two buttons on one of my VehicleDetails.aspx page. Obiviously
these two buttons takes the user to two different pages. Now my client
is interested in having a linkbutton instead of the two buttons. Once
the user clicks on the linkbutton a javascript dialog box popsup that
says "Is the Lessee buying this vehicle?" and with two buttons "Yes"
and "No". If user clicks "yes" it should go to DealerQuestions.aspx"
and if "No" it...
|
by: Marc |
last post by:
Hi,
I am using the below code which simply allows a single button control
to be dragged and dropped anywhere around a form. My problem is that
want to move about 100 buttons on the form. Is there anyway to modify
the code so that any buttons added on the form will be able to be
dragged and dropped?
Many Thanks!
|
by: Ron |
last post by:
I want to create 10 buttons on a form at runtime, the code below is
only creating one button labeled 1. Any idea what I am doing wrong?
Public Class Form1
Public code(10) As String
Public buttons(10) As Button
Const buttonwh As Integer = 30
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
|
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: 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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |