473,795 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic control Command Event won't fire first time!

149 New Member
Hi,

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

I have attached a CommandEventHan dler 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 1761
r035198x
13,262 MVP
Hi,

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

I have attached a CommandEventHan dler 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 New Member
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
7934
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 header of the datagrid in the "ItemDataBound" method of the grid. However, once, they are added in the grid, i seem to lose the event handler for the same control. Is there anyone who has tried this before and knows why this is hapenning ??
1
17679
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 Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
6
4480
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 clicked. I have read several posts which say to put your column generating section in the Page_Init section and it will solve the problem....however, it hasn't solved mine. Can somebody please take a look at this and provide any insight if possible?
1
7588
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 dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
1
8167
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 first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
13
3680
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 first starts, but when I click on a button, and the page comes back, my dynamically created grid and controls are not visible. Any thoughts? Please view my sample code below. If Not ispostback then creategrids end if
1
2158
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 fires Click event first time it is selected. The second (andd successive) times the user control is added the button Click event does not fire the first time, only on the second and successive times. This problem is caused by the naming of the...
4
4162
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 any answers?? Regards,
1
2508
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 after the post back. The table is dynamically generated based on a key field that is stored in ViewState. This key field is updated by several other controls on the same page. I am struggling with the pattern of when to create the table. I can't...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.