Say you have a Button in your Web form, with OnClick bound to a code-behind event.
You then move that button up into the master page, by adding it to the Controls collection of a control in the master page. This is done at run-time, in the Page_Load event.
Where is the OnClick event bound to now? Still the code-behind of the Web form, or is it looking in the code-behind of the master page?
I did just this, and now my button doesn't do anything. It posts the page back, but doesn't actually run the bound event in the code-behind.
I checked the HTML of the button in both cases. The only thing that changed was the ID and the name, to reflect the change in naming container:
In the Web form ("MainContent" is a ContentPlaceholder):
<input type="submit" id="ctl00_MainContent_DeleteButton" value="Yes, Delete" name="ctl00$MainContent$DeleteButton"/>
In the master page:
<input type="submit" id="ctl00_DeleteButton" value="Yes, Delete" name="ctl00$DeleteButton"/>
I have run the debugger and can confirm that it's not touching the bound event any longer.
Is it the ID or the name that binds it to an event? If so, will my moving it into the master page break this binding?
What binds a control to a codebehind event is an attribute (ex: <asp:Button ... OnClick="btnSubmit_click">) and this attribute seems to be missing in your examples above.
Double click on the button on your master page and it should wire up the event. If you get serious with the event handling you'll find plenty of interesting stuff too :)
If the control is in the master page, the engine will look for the event handler in the master page's code behind. Event handlers need to either be
a. declared in the same scope in which they are defined, or
b. programmatically assigned.
You might have a disconnect in your control execution lifecycle because of the move.
You said that you move the control during Page_Load, which happens AFTER postback data is processed, but before postback change notifications and handlers are fired.
Control Execution Lifecycle Reference
Also this says that it is the UniqueID that matters in postback processing, but I'm not sure about events.
Related
I have created a page in oracle apex where I have multiple regions and each region has a Submit page button.
Each submit has an ajax callback associated with it.
Will clicking on any one submit, also execute the other ajax callbacks?
In other words, when we click a Submit page button in one region, is it exclusive only to that regions ajax callback or will it execute all ajax callbacks of that page?
Button name determines value of the REQUEST attribute. If you look at the process values, you can set the "Editable Region" (which shows which region is associated with this process), as well as the request itself (under the "Server-side condition" properties; see the "When button pressed" and "Type").
So, if you create your own process which does something and set properties described above, each SUBMIT button should affect only its own region.
Unless I'm wrong, if there's only one SUBMIT button (created with its default settings) on the page, it'll affect all regions.
I have a UserControl:'TestControl' - which has one DropDownList: 'TestDDL' and a TextBox: 'TestAdditionalNotes' (there are no buttons or anything else in the Control that will cause a post back - and I don't need a postback as most of the data is client side). I have written a event handler for onSelectedIndexChange event in the Control. This control will be used in a 'Repeater Control' - Now I have a Testpage: 'Test.aspx' I have registered this user control on the test page - now what I want : When I change the DropDown list selected item in the contorl - the textbox should be visible/in visible based on my selection. But how to trigger the evenhandler on the control from the test page ?
I solved the problem... my code and the handlers where correct... it was just on that particular test page some javascripts libraries missing - which are required by the telerik rad control i.e the dropdown list... once I added those files manually... everything works...
(I figured this out by trying the control on a different page and the event was being raised).... Thanks
I'm starting writing my little app at WP7. I consider one thing. There is event "AtStart"? I want to use Textbox to display actual data with some text and I thought that event "atstart/atLaunch" will be perfect for it.
Thanks
There is no "AtStart" event - there is an Application.Launching event which is fired when your application starts up. There is also an OnNavigatedTo virtual method you can override on a page level which is invoked when a page is first navigated to. It sounds like OnNavigatedTo might be what you are looking for. At this point you can change the Text property of a TextBlock (which is identified by an x:Name) which is present in your page XAML file.
I have a aspx page that contain "asp:RequiredFieldValidator" controls;Problem that is when each of "asp:RequiredFieldValidator" controls activate and show their messages; other controls in my page don't working even "CANCEL" button!!!
i want to enable controls in my "NEXT" button MouseDown and then disable them at my "NEXT" button MouseUp.
Thanks for any other solutions...
Specifically to answer your question as stated in your title: to add additional event handlers to an asp:button or other server controls that are not composite you simply add the handler to the element. Include onmousedown="myMouseDownHandler(this);" in the element and the javascript function myMouseDownHandler will fire.
However, I think there is a better way to do what your asking but the description of the question is not coherent enough for me to quite figure out what you're asking. I realize you may not be a native English speaker but perhaps you could give it another pass.
Use ValidationGroup property on controls that are validated and controls that triggers validation (e.g. save/update buttons) and on validators. Additionally set CausesValidation property to false on each button that does not need to trigger validation (cancel button).
I have a html table in my application that shows the state of various jobs running in the system. Each job has a state associated with it e.g a swirly gif for running jobs. New jobs have a checkbox next to them that allows the user to select and kick off the associated job.
The table is a struts2 auto refreshing div (sx:div), it refreshes every few seconds to reflect what is currently happening with the jobs.
The problem is that when the div refreshes I lose that state of the checkboxes.
Is there an elegant way of maintaining their state? I have the option of calling some javascript upon completion of the ajax refresh using the dojo topic system built into the tag but i'm not sure what is the best way to approach it.
I'm not very familiar with struts so take me advice for what it's worth.
There are two ways to approach this that I see.
The first (and probably simplest) is to add an event to the checkboxes which stores the checked state in an array or object onchange. Then, on callback from the ajax refresh, restore those states.
The second approach would require that the ajax refresh either be executed as a post so that the checkboxes are submitted to the server, or having a separate ajax action which fires off when a checkbox is checked. With either of these options, the ajax refresh could "know" at render which checkboxes to render as checked.
If you decide to go with number one, the javascript is not very difficult, especially if you happen to be using a good library (jquery, etc.).