471,338 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 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 6061
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Henrik Nordgren | last post: by
3 posts views Thread by Jeffrey A. Voigt | last post: by
7 posts views Thread by UGH | last post: by
7 posts views Thread by Tigger | last post: by
1 post views Thread by treelife | last post: by
2 posts views Thread by momo | last post: by
reply views Thread by rosydwin | last post: by

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.