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

Dynamic control Command Event won't fire first time!

149 100+
Hi,

I am dynamically creating controls as part of a paging system for a grid view in an updatepanel.

I have attached a CommandEventHandler to the control. So far so good!

But when a click on the Dynamic control (LinkButton) first time it doesn't fire the event. I have read the page DOM and it seems that the button changes ID after the first click and then stays the same.

Why does the ID change? And is this the reason it doesn't fire the first event?

Thanks in advance for any help!
Nov 1 '07 #1
2 1728
r035198x
13,262 8TB
Hi,

I am dynamically creating controls as part of a paging system for a grid view in an updatepanel.

I have attached a CommandEventHandler to the control. So far so good!

But when a click on the Dynamic control (LinkButton) first time it doesn't fire the event. I have read the page DOM and it seems that the button changes ID after the first click and then stays the same.

Why does the ID change? And is this the reason it doesn't fire the first event?

Thanks in advance for any help!
Any chance that you are going to post the code that's misbehaving?
Nov 1 '07 #2
rsdev
149 100+
Yep! No Problem.

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$linkspagingButton1','')">1</A></TD>
  40. <TD>/</TD>
  41. <TD><A id=ctl00_CMS_CMSControl_1_linkspagingButton2 href="javascript:__doPostBack('ctl00$CMS$CMSControl$1$linkspagingButton2','')">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$ctl04$linkspagingButton1','')">1</A></TD>
  49. <TD>/</TD>
  50. <TD><A id=ctl00_CMS_CMSControl_ctl04_linkspagingButton2 href="javascript:__doPostBack('ctl00$CMS$CMSControl$ctl04$linkspagingButton2','')">2</A></TD></TR></TBODY></TABLE></DIV>
  51.  
Let me know if you need more!

Thanks.
Nov 1 '07 #3

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

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
6
by: Mark | last post by:
I have been working for quite some time on this issue which in theory should be quite simple. The problem is that the Cancel and Save events are not fired when their respective buttons are...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
13
by: Chris Thunell | last post by:
I have created several grids dynamically and have added them to different HTML placeholders on a vb.net web form. The grids and controls within them come up and view beautifully when the web page...
1
by: Steve Booth | last post by:
I have a web form containing a button that when selected adds a user control to a place holder. The user control contains a button. The first time the user control is added the contained button...
4
by: EvelynAnd Ethan | last post by:
Hi, ItemCommand event not firing from a dynamic user control ,WHERE A DATAGRID HAS BUTTON,when i click on the linkbutton first time the itemcommand event doesnt fire,second time event fires up ...
1
by: Andrew Robinson | last post by:
I have a <asp:table> control with a large number of dynamically created LinkButtons. I am using the command event, command name and command argument values in my LinkButtons to trigger actions...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
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.