dynamic controls + ajax

G

Gui

Hi, I'm working in C# .net 2005 with Ajax.

I have a page that loads dynamic user controls depending on the
scenario. In those user controls, I create dynamic linkbuttons. The user
controls are loaded on the .aspx PageLoad and the linkbuttons are
created on the .ascx PageLoad. The problem I have is that those
linkbuttons don't work on the first click. I have to make 2 clicks to
have their event fired. What can I do for that ?

Thanks.
 
Y

Yuriy Solodkyy

Hi

Do you remove any dynamically created controls from the page or ASCX in response
to any server event?
Do you assign IDs to the dynamically created link buttons?

It is possible that IDs of dynamically created controls change and server
even is not fired in response to click if you re-create link buttons with
different ID. It is possible if you change structure of the page.

-yuriy
 
G

Gui

Well, I my buttons have an ID, but I've just found that their ID change
after the first click. When they load the first time, I have something
like id="ctl05_btnGroup1", "ctl05_btnGroup2", etc. After the first
click, they change to id="ctl04_btnGroup1", "ctl04_btnGroup2", etc.

I've compared the complete source code between "Before" and "After"
first click and there are some differences in the ViewState and
everywhere I have ctl05 in the first source, it became ctl04 in the
second. Do you have any idea why it changes like that ?

Right now, I don't think I remove dynamically created controls. I'll
look again.

thanks
 
G

Gui

How can I make sure that the ID's will not change since the "ctl05" part
is generated by aspnet ? I tried creating them on Page_Init instead of
Page_Load but no success... I have like 5 placeholder that load user
controls dynamically, but I never have 2 user controls loaded at the
same time... I don't understand why the IDs are changing by themselves...
 
Y

Yuriy Solodkyy

What control do 'ctl04' and 'ctl05' prefixes come from? Is it a repeater
or something else?
It looks like before the first click you page contained some other control
before. After the first click this control was not longer created. I beleive
that this is due to change in your scenario. If you can assign unique IDs
to these controls (Naming containers for your buttons) it should solve your
problem.

-yuriy
 
G

Gui

Ok, I think I've found out the problem. Those "ctl05" came from the
PlaceHolder. The problem I got was because I was loading the user
control two times in a row the first time I loaded it. So after the
first "two loading", when I clicked on a link button, it loaded the page
only once and after that it was working. I found out a way to prevent
this and it seems to work correctly now !

Thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top