Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Seemingly no rhyme or reason to event handler

Posted on 2008-10-21
7
Medium Priority
?
232 Views
Last Modified: 2010-04-14
I have a link button that I am signing-up for (to respond to its click-event) in Page_Init:

protected void Page_Init( object sender, EventArgs e )
{
      this.ReturnLinkButton.Click += null;
      this.ReturnLinkButton.Click += new EventHandler(ReturnLink_Click);
}


Event Handler:
  protected void ReturnLink_Click(object sender, EventArgs e)
  {
    if (this.RemoveLastDisplayOverride(WorkflowSessionManager.CurrentContext.DisplayOverride))
      WorkflowSessionManager.CurrentContext.DisplayOverride = null;
  }


Sometimes when I click on the Link Button the event fires and the handler is entered.  Then I'll click it again and nothing happens.

What can I do to ensure that a click on the Link Button will always get handled?
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 7

Accepted Solution

by:
the_bachelor earned 1000 total points
ID: 22771573
this maybe a dumb question from me but are you adding the Linkbutton to the page dynamically?
If you aren't, how about a good old

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles LinkButton1.Click

    End Sub
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 22771824
Sorry, this is in C#.

But as far as I know ...  I am doing what you suggest.
0
 
LVL 2

Assisted Solution

by:johnhumenik
johnhumenik earned 1000 total points
ID: 22772177
What version of VS are you using?  In VS 2005/2008 the event handler declaration doesn't exist in C# code, but on the aspx page using the OnClick="<eventname>".
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 22772195
I am in Visual Studio 2008.


I have tried it that way, also .... same thing.

For example, RIGHT NOW my markup looks like this:


 <asp:LinkButton ID="ReturnLinkButton" runat="server" onclick="ReturnLinkButton_Click" />


Code Behind looks like this:


  protected void ReturnLinkButton_Click( object sender, EventArgs e )
      {
            if (this.RemoveLastDisplayOverride(WorkflowSessionManager.CurrentContext.DisplayOverride))
                  WorkflowSessionManager.CurrentContext.DisplayOverride = null;
      }


And yet, when I first visit the page at runtime, the code execution does not stop at the breakpoint I have set on the first click.  But subsequent clicks DO stop.  Obviously that is not acceptable.
0
 
LVL 2

Expert Comment

by:johnhumenik
ID: 22772407
can you post your entire code behind or is it too long?
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 22773285
One thing a co-worker and I discovered while debugging is that the naming for the LinkButton is changing between postbacks.  It is named one thing after the first postback and another after the next postback.  This would explain why the event is not firing consistently, for the event handler depends upon the name of the control.

First postback:

"ctl00$mainContent$ctl05$ReturnLinkButton"


Second postback:

"ctl00$mainContent$ctl01$ReturnLinkButton"


What we don't know is how to fix this.  Is there a way to force the naming for the control to remain consistent across postbacks?
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 22791360
As it turns-out ... the problem WAS indeed with the naming of the control ID  (or better said, the total lack thereof).

Now I assign the ID in the parent control as the child control (the one that had the problem with the event handler) is added to the Controls collection:
 // Account Review
      if (c is UserControls_Workflow_Account)
      {
				((UserControls_Workflow_Account)c).ID = "AccountControl";
        ((UserControls_Workflow_Account)c).NavigateRequested += new CommandEventHandler(controlSearchResults_NavigateRequested);
        ((UserControls_Workflow_Account)c).UpdateAccount += new UpdateAccountEventHandler(controlAccount_UpdateAccount);
      }

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question