• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Event not getting thrown C#

AyashiKaibutsu

Diamond Member
Code:
        Button releaseNumber = new Button();
        releaseNumber.CssClass = tempRow.CssClass;
        releaseNumber.Text = connection.DataReader["Release_Number"].ToString();
        releaseNumber.BorderWidth = 0;
        releaseNumber.ForeColor = System.Drawing.Color.Blue;
        releaseNumber.Click += new EventHandler(SelectReleaseFromTable);
        tempRow.Cells[0].Controls.Add(releaseNumber);

Event doesn't get thrown when I click the button. I can comment out the add event line and the program acts the same way.
 
Last edited:
Are you using WPF? Try using a routedEventHandler like
Code:
releaseNumber.Click += new RoutedEventHandler(SelectReleaseFromTable);
 
Are you using WPF? Try using a routedEventHandler like
Code:
releaseNumber.Click += new RoutedEventHandler(SelectReleaseFromTable);

It's for a webpage, and I'm not too familiar with WPF (just googled it now). I'll give that a try when I get back to work tomorrow (no access from home).
 
Some more context from the page would be useful. If you're manually wiring up events you have to be careful about when/where you do that. First, you have to wire it up every time; you can't skip it on postback. Second, you have to wire it up before the client-side events are processed on the server, meaning that page_load is too late, I believe. You also have to give the button an ID, as joshsquall mentioned, because that's how the pipeline figures out what event a client-side action maps to on the server. Anyway, it's very likely one of these things, so post some more of the page and we'll take a look.
 
Some more context from the page would be useful. If you're manually wiring up events you have to be careful about when/where you do that. First, you have to wire it up every time; you can't skip it on postback. Second, you have to wire it up before the client-side events are processed on the server, meaning that page_load is too late, I believe. You also have to give the button an ID, as joshsquall mentioned, because that's how the pipeline figures out what event a client-side action maps to on the server. Anyway, it's very likely one of these things, so post some more of the page and we'll take a look.

Kk and thanks. I'll give that stuff a try and try to post more of it tomorrow. I don't have access to the source code at home.
 
So, the button I'm trying to make doesn't exist when the page is first loaded. It's in a table I populated with info the user searches for; don't know how I'd do that before page_load.
 
Last edited:
Well, you're going to have to carefully consider the life cycle of the page, especially when using one page to do multiple jobs like accepting a search form and displaying the results. The bottom line is that you can't handle an event from a control that hasn't been created at the time events are processed, and that doesn't have the same ID it had on the page that posted the event back to the server. It's been awhile since I did any intensive ASP, so maybe someone else here can give you some ideas. My recommendation would be to get a really good handle on the flow as a page is created. Remember that it is recreated on each request. There's no state other than what is persisted in the view state, or what you persist in session variables. So you have to line things up right so that the engine knows what control to pass an event to. Pretty certain that's your problem.
 
Back
Top