473,382 Members | 1,545 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,382 software developers and data experts.

Help in asp.net addhandler

Hi, I create an dynamic command button like that:
buttonCmd= New Button
buttonCmd.ID = "IDBTN1"
buttonCmd.Text = "Test"
AddHandler buttonCmd.Click, AddressOf MessageClick

I have this click sub:
Sub MessageClick(ByVal sender As Object, ByVal e As System.EventArgs)
'Do something
End Sub

For the first try I create this dynamic button on time in the form load
between
If Not Page.IsPostBack Then

Jul 21 '05 #1
5 6178
Sorry I hit the Post buttun!

Here is the next part of my answers...

Like I said, I put the dynamic button in the
if not page.isPostBack then
'create the button
end if

When I hit the button, nothing append and my button disapear. I think that
my buttun is lost in the postbak add for that reason the event added by the
addhandler is not fired...

I change my code to initialize the button and add the handler in the
page_load without the if not page.isPostBack limitation.
When I start the web page I I click on the button I receive this error:

Multiple controls with the same ID 'IDBTN1' were found. FindControl requires
that controls have unique IDs.

Why? The postback is not supposed to lost this control? How can I fire my
event?

Thanks for your help
Jul 21 '05 #2
Pierre,

Dynamically created controls need to be re-created in code upon every
request to the page AND it has to be re-created before the Page_Load() event
fires, I suggest you override the Init() and put your code to create the
button in that method.

HTH,
Jorge

"Pierre" wrote:
Sorry I hit the Post buttun!

Here is the next part of my answers...

Like I said, I put the dynamic button in the
if not page.isPostBack then
'create the button
end if

When I hit the button, nothing append and my button disapear. I think that
my buttun is lost in the postbak add for that reason the event added by the
addhandler is not fired...

I change my code to initialize the button and add the handler in the
page_load without the if not page.isPostBack limitation.
When I start the web page I I click on the button I receive this error:

Multiple controls with the same ID 'IDBTN1' were found. FindControl requires
that controls have unique IDs.

Why? The postback is not supposed to lost this control? How can I fire my
event?

Thanks for your help

Jul 21 '05 #3
ok, but the example I post is verry simple, but in the real life, the number
of command button are deternimed by some querys to an SQL database in
function of the user logged in (form authentication).
Plus the command button are created in a cell of a static asp table. This
table is created before the Page_Init sub? I will be able to acces it and
populate it?

"Jorge L Matos [MCSD.NET]" wrote:
Pierre,

Dynamically created controls need to be re-created in code upon every
request to the page AND it has to be re-created before the Page_Load() event
fires, I suggest you override the Init() and put your code to create the
button in that method.

HTH,
Jorge

"Pierre" wrote:
Sorry I hit the Post buttun!

Here is the next part of my answers...

Like I said, I put the dynamic button in the
if not page.isPostBack then
'create the button
end if

When I hit the button, nothing append and my button disapear. I think that
my buttun is lost in the postbak add for that reason the event added by the
addhandler is not fired...

I change my code to initialize the button and add the handler in the
page_load without the if not page.isPostBack limitation.
When I start the web page I I click on the button I receive this error:

Multiple controls with the same ID 'IDBTN1' were found. FindControl requires
that controls have unique IDs.

Why? The postback is not supposed to lost this control? How can I fire my
event?

Thanks for your help

Jul 21 '05 #4
OK I make the test. I place the function that populate the static table and
create the dynamic button. All work good for acceding the static table to
when I hit the button a got the same errer :

Multiple controls with the same ID 'BTN11' were found. FindControl requires
that controls have unique IDs.

"Pierre" wrote:
ok, but the example I post is verry simple, but in the real life, the number
of command button are deternimed by some querys to an SQL database in
function of the user logged in (form authentication).
Plus the command button are created in a cell of a static asp table. This
table is created before the Page_Init sub? I will be able to acces it and
populate it?

"Jorge L Matos [MCSD.NET]" wrote:
Pierre,

Dynamically created controls need to be re-created in code upon every
request to the page AND it has to be re-created before the Page_Load() event
fires, I suggest you override the Init() and put your code to create the
button in that method.

HTH,
Jorge

"Pierre" wrote:
Sorry I hit the Post buttun!

Here is the next part of my answers...

Like I said, I put the dynamic button in the
if not page.isPostBack then
'create the button
end if

When I hit the button, nothing append and my button disapear. I think that
my buttun is lost in the postbak add for that reason the event added by the
addhandler is not fired...

I change my code to initialize the button and add the handler in the
page_load without the if not page.isPostBack limitation.
When I start the web page I I click on the button I receive this error:

Multiple controls with the same ID 'IDBTN1' were found. FindControl requires
that controls have unique IDs.

Why? The postback is not supposed to lost this control? How can I fire my
event?

Thanks for your help

Jul 21 '05 #5
Nothing more to help?

"Pierre" wrote:
OK I make the test. I place the function that populate the static table and
create the dynamic button. All work good for acceding the static table to
when I hit the button a got the same errer :

Multiple controls with the same ID 'BTN11' were found. FindControl requires
that controls have unique IDs.

"Pierre" wrote:
ok, but the example I post is verry simple, but in the real life, the number
of command button are deternimed by some querys to an SQL database in
function of the user logged in (form authentication).
Plus the command button are created in a cell of a static asp table. This
table is created before the Page_Init sub? I will be able to acces it and
populate it?

"Jorge L Matos [MCSD.NET]" wrote:
Pierre,

Dynamically created controls need to be re-created in code upon every
request to the page AND it has to be re-created before the Page_Load() event
fires, I suggest you override the Init() and put your code to create the
button in that method.

HTH,
Jorge

"Pierre" wrote:

> Sorry I hit the Post buttun!
>
> Here is the next part of my answers...
>
> Like I said, I put the dynamic button in the
> if not page.isPostBack then
> 'create the button
> end if
>
> When I hit the button, nothing append and my button disapear. I think that
> my buttun is lost in the postbak add for that reason the event added by the
> addhandler is not fired...
>
> I change my code to initialize the button and add the handler in the
> page_load without the if not page.isPostBack limitation.
> When I start the web page I I click on the button I receive this error:
>
> Multiple controls with the same ID 'IDBTN1' were found. FindControl requires
> that controls have unique IDs.
>
> Why? The postback is not supposed to lost this control? How can I fire my
> event?
>
> Thanks for your help

Jul 21 '05 #6

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

Similar topics

0
by: Henrik Nordgren | last post by:
Im trying to build a simple chat app... here is the code: server visual basic code:-------------------------------------------------------------------------------- Public Class ChatServer ...
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...
7
by: UGH | last post by:
I am adding image buttons dynamically and I need to add event handler when the user clicks on one of those image buttons which will have different id for reports. Here is my code LnkImage =...
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...
2
by: Sean Carey | last post by:
I converted a C# Upload app to VB.NET and am down to one error and was hoping someone could help me with te error. I would greatly appreciate help from anyone. Here is the error: ...
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...
0
by: richard | last post by:
OK, Im finished pulling my hair out and now I need help. I have created a VB class file for my custom paging, in it I create a table with 2 rows, in the rows I have linkbuttons for first page,...
3
by: RobinS | last post by:
I'm trying to learn WPF and do it in VB instead of C#. (God forbid I should do *anything* the easy way. ;-) Here's something weird. On p162-3 of this book by Petzold (in C# of course) in an...
4
by: Ty | last post by:
Hello all, I am creating a website in VS 2008 VB.net. On one of my pages I am using the Table control to make a type of calendar a IN/OUT board. The problem I found after I wrote all the code...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.