WPF + UserControl + OnClosing event - c#

I write an application in WPF where I have one main page and one user control in it. I need to call function when I close the page where user control is embedded. I can't call this function from the main page, I need to do it directly in user control (as I don't have access to main page). There is an event unloaded for user control, but it is called to late. How can I get something like onclosing event?

Related

How to call a full postback after the execution of the button click event inside an user control?

Okay,
I have this scenario:
There is a user control with an update panel within it. There is a button within that update panel with proper postback trigger being set. The button_click event is also defined well. I need to call a full postback of the parent aspx page once the "button_click" event is completed. Under ideal case, all the form submission events such as postbacks occur before event based methods are executed. This means my page will first be reloaded then the button click event will be executed. I want something like to reverse this operation. First Button_click event execution then one postback after that on the aspx page(this page calls the user control-> and this user control has the updatepanel with button in it).
Any possible way out would be highly appreciated.
I don't think there's a way to change ASP.NET's lifecycle, like the one you described. A (dirty) way of postbacking the parent page is however to put a hidden button on that page, and call it via javascript in the UC. (via ScriptManager.RegisterStartupScript)

How can I invoke OnInit event of UserControl?

my situation is a little complicated. What I'm trying to do is make reload UserControl (with dynamically changed control inside my UserControl). It's simple when I trying to do it OnInit or Page_Init event of my Page. But I need to do this inside a click event of button which by the way is ext.net type and have build in callback events.
So is there any way to invoke OnInit event of UserControl on event click raise?
If any more information needed pls feel free to ask in comments:)
Thanks for advance:)
I think you should manage this case differently.
OnInit is fired according to the webform life-cycle, in which each step has a specific purpose :
http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx
During page initialization, controls on the page are available and
each control's UniqueID property is set. A master page and themes are
also applied to the page if applicable. If the current request is a
postback, the postback data has not yet been loaded and control
property values have not been restored to the values from view state.
You'd better not 'force' this concept, try to adapt your code to meet the flow constraints.

Remove original event behaviour of WinForm Control

I would like to remove the original event behavior of controls within a form (similar to design mode).
So, when the user clicks on the button, i only want to capture that event. I do not want the original button event to be fired. Is this somehow possible?
I am looking for a generic solution. So it should work with any form and any control within the form.
Reason: I wrote a form validation rules designer. It uses reflection to enumerate all form-types in the entry assembly. The user can then select a form type, the designer creates that form, enumerates the controls, and embedds the form in the designer panel.
clicking on a control, opens a formular designer panel, and the user can now create a formular for that control and saves the formular to a DB.
When the form is then opened in the normal "runtime" mode, it loads its validation formulars.
Events are not in fact disabled in the Winforms designer. The designer executes the constructor of the form through Reflection, everything in the InitializeComponent() method executes, including the event subscriptions. Wherever this might cause a problem, the controls check the DesignMode property (prevents a Timer from starting for example) or by custom designers. The form is displayed underneath a transparent layered window on top of which the selection rectangle and drag handles are painted. Which prevents issues with mouse clicks and keyboard focus.
You probably ought to look at this magazine article to get this working for you.
From what I understand from your question, I guess, you can still use the "DesignMode" property for this as well. In your event handling routine, you may want to bypass execution by checking on this property:
if (this.DesignMode) return;
as the first statement in your event handling block of code.

C# WPF: webbrowser modal dialog close from win32 app

I am curious as to if this is even possible, but basically what I need is when opening a System.Windows.Forms.WebBrowser Modal Dialog from a WPF application I need to catch a value passed back from the page to WPF and keep a window up or close it based on the value that I return. Is this even possible or am I going to have to about in a different way?
Thanks, Andrew
surely is possible, just create the dialog, register an event handler for a custom event you have created in your second form and show it as modal, then inside your form you do what you need to do and when something happens you fire the event the main form has registered to, in the custom EventArgs class used in your event you can pass the value main form needs to get. from the main form you check the value and you do nothing or close the popup....

Custom Control loads a user control; Postback events are not triggered

I have a custom control (compiled as a DLL) which loads a user control. (i.e, the custom control does a LoadControl) In the user control is a button and a textbox. I wire up the button's click event.
I type in a value into the text box. When I click the button, the page does a postback. My user control knows that a postback occured because Page.IsPostBack = true. However, the click event of the button is never fired and my text box has also lost the value that I typed in.
Anyone have any thoughts as to what might be going on?
EDIT:
I did a test on this and took SharePoint out of the picture; I was able to reproduce it so I removed all references to SharePoint.
If you are dynamically loading the user control, you have to reload it on each page load (postback or not) in order for the .net processor to know where to wire up the submit event.
One way to load the User Control is to override CreateChildControl, call base.CreateChildControls and then call your LoadControl method. If you need to place the UserControl is a specific location, place a PlaceHolder on the page and add your control to the place holders control collection.
You can also just add the user control directly to the markup.
Register the control as such:
<%# Register Src="~/path/ControlName.ascx" TagName="tagName" TagPrefix="myPrefix" %>
and then add it in as follows:
<myPrefix:tagName ID="myId" runat="server"/>
If you are databinding, you need to check that you are only doing so on !Page.IsPostBack when you databind, you wipe out any "saved" state from the postback.
Sounds like you're not recreating the control on postback. You will need to add the control during Page_Init for the view state to be loaded.

Categories

Resources