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

AJAX UpdatePanel dynamic controls and RegisterStartUpScript click twice

149 100+
Hi,

I have read hundreds of post regarding this issue, but none have an answer for my situation. So hopefully somebody here can help!

I have a gridview in an updatepanel (AJAX control toolkit) and because paging/sorting aren't supported I've added my own custom paging. I have dynamically loaded LinkButtons in the updatepanel to change the page but they only fire on the second click. I have also attached javascript to the rows so that they can be selected when you click. Again only the second click works.

I have DataBind in the event handlers and I only DataBind the first time when the page is loaded. When I debug the click events only fire the second time??

Any ideas?

Thanks in advance
Oct 31 '07 #1
23 16120
Frinavale
9,735 Expert Mod 8TB
Hi,

I have read hundreds of post regarding this issue, but none have an answer for my situation. So hopefully somebody here can help!

I have a gridview in an updatepanel (AJAX control toolkit) and because paging/sorting aren't supported I've added my own custom paging. I have dynamically loaded LinkButtons in the updatepanel to change the page but they only fire on the second click. I have also attached javascript to the rows so that they can be selected when you click. Again only the second click works.

I have DataBind in the event handlers and I only DataBind the first time when the page is loaded. When I debug the click events only fire the second time??

Any ideas?

Thanks in advance
I'd suggest taking the GridView out of the UpdatePanel.
Is there any reason why it has to be there?


Have you attempted moving the paging LinkButtons outside of the GridView (place them above or below or something).
Oct 31 '07 #2
rsdev
149 100+
Hi Frinavale,

Thanks for responding!

I want the gridview in the updatepanel to create a seemles WYSIWYG CMS.

Once I've finished the demo I plan to open source the project and invite other developers to help improve it like a updated AJAX WYSIWYG version of DOTNETNUKE.

Anyway, the LinkButtons are outside the gridview they are dynamically created in placeholder below the gridview. But the javascript is obviously attached to each row of the gridview. So it must be a simple error on my part because both of these don't re-act on the first click. The updatepanel is in conditional mode with ChildTriggers set to true. I've read that I should create dynamic triggers for each of the dynamic controls but that doesn't explain why the javascript rows aren't working either.

I'm really stumped on this one!
Oct 31 '07 #3
Frinavale
9,735 Expert Mod 8TB
Hi Frinavale,

Thanks for responding!

I want the gridview in the updatepanel to create a seemles WYSIWYG CMS.

Once I've finished the demo I plan to open source the project and invite other developers to help improve it like a updated AJAX WYSIWYG version of DOTNETNUKE.

Anyway, the LinkButtons are outside the gridview they are dynamically created in placeholder below the gridview. But the javascript is obviously attached to each row of the gridview. So it must be a simple error on my part because both of these don't re-act on the first click. The updatepanel is in conditional mode with ChildTriggers set to true. I've read that I should create dynamic triggers for each of the dynamic controls but that doesn't explain why the javascript rows aren't working either.

I'm really stumped on this one!
I remember a while ago having the same problem (having to click twice)...but I can't remember how I got around it.

Let me see if I can't help you find something online regarding the issue.

-Frinny
Oct 31 '07 #4
Frinavale
9,735 Expert Mod 8TB
Do me a favour and try to link buttons that are not dynamically generated for your paging....does that fix anything?

And can you post the JavaScript responsible for selecting so that I can make sure there's nothing wrong here?

Just double checking before I get into looking up the event firing stuffs.
Oct 31 '07 #5
rsdev
149 100+
Hi Frinny,

Thanks for sticking with this!

I've just tried adding a LinkButton (great suggestion) and have the same problem, nothing (response.write) on the first click. It's like the first click isn't getting through to the server... somehow!

Here's the serverside added javascript;

Expand|Select|Wrap|Line Numbers
  1. protected void linksView_RowDataBound(object sender, GridViewRowEventArgs e)
  2. {
  3.             if (e.Row.RowType == DataControlRowType.DataRow)
  4.             {
  5.                 e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
  6.                 e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
  7.                 e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.linksView, "Select$" + e.Row.RowIndex);
  8.             }
  9. }
Thanks again!
Nov 1 '07 #6
rsdev
149 100+
So in order to trace what was happening to the clicks, I decided to get a hardcore debugger. The Web Development Helper is very cool!

Now when I load the gridview in the updatepanel I checked the pages DOM and get a table with ID ...CMSControl_1_linksView. When I click the button first time around the ID changes to CMSControl_ct104_linksView, then it remains the same. This has got to be the issue!!
Nov 1 '07 #7
rsdev
149 100+
In fact it gets worse because all the javascript: __doPostBack code has used '$' instead of '_' for the ID's.

So how do I stop the gridivew table from changing ID and how do change the '$' for '_'?
Nov 1 '07 #8
rsdev
149 100+
Don't worry about the '$' versus '_'. I've found out that doesn't make a difference.

But I still have the problem where I create the LinkButtons in Page_Load in a placeholder then the placeholder changes id after the first click so the event is never found or fired.
Nov 1 '07 #9
rsdev
149 100+
So now I'm stuck not knowing how to make the LinkButton __DoPostBack the correct id??

Would ParseControl work better?
Nov 1 '07 #10
rsdev
149 100+
I think it's time to re-post this thread with a more appropriate heading.
Nov 1 '07 #11
Frinavale
9,735 Expert Mod 8TB
I think it's time to re-post this thread with a more appropriate heading.
Don't repost...I'll change the title.
What would you like it to be?
Nov 1 '07 #12
Frinavale
9,735 Expert Mod 8TB
Just try one more thing for me...try taking the GridView out of the update panel...
Nov 1 '07 #13
rsdev
149 100+
Hi Frinny,

Sorry I created another post already!

But it would be great to continue and try to get to the bottom of this.

Unfortunately I can't take the gridview out of the updatepanel as I am dynamically loading it in there. The gridview is inside a user control, which is loaded into the updatepanel. I know this creates complexity but the finish result will be a seemless user experience.

The selectable rows are now working. But the paging dynamic LinkButtons are not. When they first load into the updatepanel they have a strange ID, then on the first click the ID becomes correct and they work fine.

Is there anyway to solve this?
Nov 1 '07 #14
Frinavale
9,735 Expert Mod 8TB
Hi Frinny,

Sorry I created another post already!

But it would be great to continue and try to get to the bottom of this.

Unfortunately I can't take the gridview out of the updatepanel as I am dynamically loading it in there. The gridview is inside a user control, which is loaded into the updatepanel. I know this creates complexity but the finish result will be a seemless user experience.

The selectable rows are now working. But the paging dynamic LinkButtons are not. When they first load into the updatepanel they have a strange ID, then on the first click the ID becomes correct and they work fine.

Is there anyway to solve this?
I know you were explaining this ID problem earlier.
Could you post a snippet/example of the "strange" ID and "regular" ID please?
Nov 1 '07 #15
rsdev
149 100+
Yep! No Problem.

The dynamic LinkButton is in the user controls onload event.

Expand|Select|Wrap|Line Numbers
  1. protected override void OnLoad(EventArgs e)
  2. {
  3.             //Create paging buttons
  4.             HtmlTableRow row = new HtmlTableRow();
  5.  
  6.             int numLinks = (int)Math.Ceiling((decimal)LinkInfo.numLinks / 5);
  7.             for (int i = 1; i <= numLinks; i++)
  8.             {
  9.                 pagingLink = new LinkButton();
  10.  
  11.                 pagingLink.Text = i.ToString();
  12.                 pagingLink.CommandName = i.ToString();
  13.                 pagingLink.CommandArgument = i.ToString();
  14.                 pagingLink.Command += new CommandEventHandler(GetNextPage_Click);
  15.                 pagingLink.ID = "linkspagingButton" + i.ToString();
  16.  
  17.                 HtmlTableCell cell = new HtmlTableCell();
  18.                 cell.Controls.Add(pagingLink);
  19.                 row.Cells.Add(cell);
  20.                 if (i < numLinks)
  21.                 {
  22.                     HtmlTableCell cell2 = new HtmlTableCell();
  23.                     cell2.InnerHtml = "/";
  24.                     row.Cells.Add(cell2);
  25.                 }
  26.             }
  27.             HtmlTable t = (HtmlTable)FindControl("pagingTable");
  28.             t.Rows.Add(row);
  29.  
  30.             base.OnLoad(e);
  31. }
  32.  
  33.  
  34. DOM First time
  35.  
  36. <TABLE id=ctl00_CMS_CMSControl_1_pagingTable cellSpacing=0 cellPadding=0>
  37. <TBODY>
  38. <TR>
  39. <TD><A id=ctl00_CMS_CMSControl_1_linkspagingButton1 href="javascript:__doPostBack('ctl00$CMS$CMSControl$1$li  nkspagingButton1','')">1</A></TD>
  40. <TD>/</TD>
  41. <TD><A id=ctl00_CMS_CMSControl_1_linkspagingButton2 href="javascript:__doPostBack('ctl00$CMS$CMSControl$1$li  nkspagingButton2','')">2</A></TD></TR></TBODY></TABLE></DIV>
  42.  
  43. DOM Second time
  44.  
  45. <TABLE id=ctl00_CMS_CMSControl_ctl04_pagingTable cellSpacing=0 cellPadding=0>
  46. <TBODY>
  47. <TR>
  48. <TD><A id=ctl00_CMS_CMSControl_ctl04_linkspagingButton1 href="javascript:__doPostBack('ctl00$CMS$CMSControl$ctl0  4$linkspagingButton1','')">1</A></TD>
  49. <TD>/</TD>
  50. <TD><A id=ctl00_CMS_CMSControl_ctl04_linkspagingButton2 href="javascript:__doPostBack('ctl00$CMS$CMSControl$ctl0  4$linkspagingButton2','')">2</A></TD></TR></TBODY></TABLE></DIV>
Then I've including the DOM info for pre and post first click.

Let me know if you need more!

Thanks.
Nov 1 '07 #16
Frinavale
9,735 Expert Mod 8TB
I'm still looking up what may be causing this.
It doesn't seem to make any sense that this would be a problem.
Your ID's look fine to me (?)

Anyways, I'm still looking...can't find what I did to solve my problem...and am having problems finding anything online.

Are you using VS2005?
You've probably already done this but....have you used the debugger to see if the the page even posts back when you click the button?
Nov 1 '07 #17
Frinavale
9,735 Expert Mod 8TB
Oh yeah...from what I remember your "response.write" wont work properly in partial page updates. I suggest using a label and setting it's text to something instead of using response.write.




:)
Nov 1 '07 #18
rsdev
149 100+
The ID that causes the problem is here;

before click id=ctl00_CMS_CMSControl_1_linkspagingButton2

after click id=ctl00_CMS_CMSControl_ctl04_linkspagingButton2

The control exist in the table

id=ctl00_CMS_CMSControl_1_pagingTable

Which ID changes to

id=ctl00_CMS_CMSControl_ct104_pagingTable

So I'm deducing that because the control is posting an async javascript post back.

javascript: __DoPostBack('ctl00_CMS_CMSControl_1_linkspagingBu tton2','')

The IDs on post back don't match because the ID should be.

ctl00_CMS_CMSControl_ct104_linkspagingButton2

Does this make sense?
Nov 1 '07 #19
Frinavale
9,735 Expert Mod 8TB
The ID that causes the problem is here;

before click id=ctl00_CMS_CMSControl_1_linkspagingButton2

after click id=ctl00_CMS_CMSControl_ctl04_linkspagingButton2

The control exist in the table

id=ctl00_CMS_CMSControl_1_pagingTable

Which ID changes to

id=ctl00_CMS_CMSControl_ct104_pagingTable

So I'm deducing that because the control is posting an async javascript post back.

javascript: __DoPostBack('ctl00_CMS_CMSControl_1_linkspagingBu tton2','')

The IDs on post back don't match because the ID should be.

ctl00_CMS_CMSControl_ct104_linkspagingButton2

Does this make sense?

Hmm...let me think about this for a sec...

In the mean time... found this tadbit of information:
...in some circumstances, a control might not work as expected inside an UpdatePanel control. These circumstances include the following:

Registering script by calling registration methods of the ClientScriptManager control.
Rendering script or markup directly during control rendering

If the control calls script registration methods of the ClientScriptManager control, you could use corresponding script registration methods of the ScriptManager control instead. In that case, the control can work inside an UpdatePanel control.
Doesn't help with your ID's being changed though.
Nov 1 '07 #20
Frinavale
9,735 Expert Mod 8TB
Hmm...let me think about this for a sec...

In the mean time... found this tadbit of information:


Doesn't help with your ID's being changed though.
Actually that might be the problem.
I remember that if you register a JavaScript for some control...that that JavaScript will not work for the control...and upon debugging the issue it was because the names of the controls get changed slightly...so the JavaScripts can't work properly.

You aren't actually supplying "_doPostBack" JavaScript methods for these LinkButtons are you????
Nov 1 '07 #21
rsdev
149 100+
No. I copied these values from the DOM they are created by .NET in the Page life-cycle, when I create the dynamic controls (OnLoad).

For some reason the first time they are created the ID is different to the second time. Then from the secodn time onwards they remain the same.

The 1 swaps with ct104 I think this is the Client ID for either the UpdatePanel or the placeholder inside it.

The only solution I can think of is to somehow fake a postback after the first load to enable the IDs to be updated. Seems like the wrong solution!
Nov 1 '07 #22
rsdev
149 100+
Hmmm!

Just seen your post before the last one.

I am registering a ClientScript in the Page_Load method which resizes the and centers the DIV around the gridview. I'll try running without this script.

I'll have to post back tomorrow as it's getting late in the French Alps.

If you can think of any other helpful links I would be most grateful.

Thanks again.
Nov 1 '07 #23
rsdev
149 100+
SOLVED!!

When dynamically adding the user control to the placeholder I was assinging an ID, in this case 1. But when I persisted the control on PostBack I wasn't assigning an ID. Doh!

I'm so used to assigning ID's to dynamic controls that I'd done the same thing with the user control. Which I suppose is fine, except if you don't assign the same ID on when the control persists.

Thanks for your help! The link to ASP.NET AJAX got me thinking and lead to the solution.

I also noticed it's possible to dynamically load a control directly to ContentTemplateContainer and cut out the placeholder altogether.
Nov 2 '07 #24

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: brett | last post by:
I have an AJAX updatepanel in an aspx page. Inside the updatepanel is a placeholder control, which loads various ascx files. This all works fine. One of the ascx files also has an updatepanel in...
4
by: Rob Meade | last post by:
Hi all, I played with my first bit of AJAX the other week and was pleasantly surprised that I achieved my goal..now I'd like to try something else.. Question... If I have an updatePanel,...
8
by: =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?= | last post by:
I am new to AJAX. I am applying AJAX to a current web solution to get the "instant behaviour". On my main page I have two sets of criteria: Specific and Wide. Each set is placed in a View...
2
by: =?Utf-8?B?VG9u?= | last post by:
Hello, I want to understand teh benefits of ajax technology. Does anyone has a good website where AJAX EXTENSIONS is worked out so I really understand it. There a 2 main questions: 1) How about...
3
by: JacekDr | last post by:
Hello, I've got the following problem: I want to add and remove dynamically controls to UpdatePanel. In my user control I have a button, but when I click it I get AsyncPostback and Event for...
7
by: MikeB | last post by:
Hello All, I am new to ajax and wanted to start by trying something simple. I have a web form with an updatepanel and then inside the update panel I have a listbox. Then outside of the updatepanel...
1
by: abellix | last post by:
An updatepanel contains a datagrid, this datagrid has columns generated by code-behind: some columns should have async postback, others should have sync postback. Here a sample to reproduce the...
4
by: Peter | last post by:
ASP.NET I have an application which use ASP.NET Autocomplete extender which works great. But I have a question how to update all the fields on the screen using Ajax. Users starts typing in a...
1
by: raam | last post by:
Hi, I have ajax tab container with 6 tabs in it. I need to validate each tab contents separately and the validtaion summary must be separate for each tab. i cannot do that only one summary is...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.