ASP.Net & jQuery - closing a popup - c#

I want to close a ShadowBox popup when the user clicks a button. The popup is showing a separate page in an Iframe.
This works fine with a clients-side event on the Cancel button control, e.g.
OnClientClick="javascript:parent.Shadowbox.close();"
The Ok button, however, has a server-side event, because data needs to be saved. When I define both an OnClick and the OnClientClick handler from above, the IFrame is closed and the server-side event handler never fires.
I tried to remove the OnClientClick event handler from the markup and to use the ClientScriptManager to accomplish this, as in
Page.ClientScript.RegisterStartupScript(this.GetType(),
"Close", "parent.Shadowbox.close();", true);
Apparently because the buttons are in an UpdatePanel, the script does not get registered, and it does not appear in the Reponse stream. The IPanel stays open.
How can I do this?

When you're using the MS AJAX controls, you need to register your scripts with the ScriptManager, not ClientScript.

Related

How to call a button click of another aspx page in code behind?

How to call Button.Click of one Page from another Page, both pages are open. Second page is a ClientScript.RegisterStartupScript popup from the first page.
When I click button in second page, the ClientScript popup should close and also it should fire Button.Click event in First Page.
Not possible that easy. You can't call an event handler on another page's controls, and it sounds like a terrible design in my opinion.
I would suggest to move the contents of that event handler to another class, separate from the pages' code behind files and call it from the page you are in.
Other options could include javascript solutions, but you clearly statement you don't want to use those. Else, this could be a solution to close the window. For calling the event handler on 'page 1' you could do a postback.

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 to handle JavaScript's confirm dialog box on GridView's PageIndexChanging event?

What I'm trying to do is when the user tries to go to a different page inside a GridView control, I want to display JavaScript's confirm dialog box. If the user clicks on OK then the page should change. If not the page should not.
What I've done at the moment is display the confirm dialog box when the GridView 's PageIndexChanging event is fired, but I can't seem to find a way to check which button was clicked on in the confirm dialog box and how to handle it.
Also, the GridView is inside an UpdatePanel and the ScriptManager.RegisterStartupScript method is being used to display the confirm dialog box.
First, you need to register your script in the scriptmanager's DataItem list. Then create the client side scripting that handles this event.
You can also do so via the following method: ScriptManager.RegisterClientScriptBlock. Here is its documentation.
You can refer to some samples.

updating updatepanel's based on texbox focus lost in asp.net

I have an asp.net page with two user controls. Each of which are in separate updatepanel's One user control has three textboxes. I want to update the second updatepanel based on change of text/ focus out in first user control. How can I access both user control's textboxes, and other controls in page and update the updatepanel on change of text ?
updatepanel1
user control1
textbox1
textbox2
textbox3
updatepane2
usercontrol2
label1
Regards,
Asif Hameed
Whoa, UpdatePanels! That takes me back. Triggering UpdatePanels to "postback" asynchronously from the client has always been a bit of a kludge. The common way was to register an AsyncPostBackTrigger with a hidden button's click event and then explicitly call its click event on the client side. However, a solution with a few less layers of indirection is to call the ASP.NET AJAX library's __doPostback() JS function.
Assuming you're using jQuery (which may be far-fetched considering you're still using UpdatePanels!), you can add an event handler to the 'focusout' event of your UserControl1 to trigger the asynchronous postback of your UpdatePanel2. I would recommend putting this JS outside of one of your UpdatePanels.
$('#userControl1').on('focusout', function() {
__doPostback('UpdatePanel2UniqueId', '');
});
I dug up a good article that explains the technique of using __doPostback in a bit more detail.
Easily refresh an UpdatePanel, using JavaScript

disable/enable buttons

I'm working in ASP .Net. I need to be able to click a button, disable it, have the code behind kick in and execute some functions and once they are done, enable the button again. There is no postback taking place per say in this project as we are using an UpdatePanel. About as far as I've been able to get successfully is using this syntax to disable it on the code behind Page_Load function:
btnConnect.Attributes.Add("onClick", "document.body.style.cursor = 'wait';this.disabled = true;" + ClientScript.GetPostBackEventReference(btnConnect, string.Empty) + ";");
This disables the button and allows the code behind to execute. I just can't figure out how to re-enable the button once the functions that run in the code behind are done. Is there a way to capture when the code behind is done?
Are you able to use jQuery instead? Consider a flow like this:
on click, disable button
call/POST to an ASP.NET URL as needed
re-enable the button when the URL call returns. Update page elements, redirect, alert as needed.
You can use a timeout approach after the disable:
var that = this; //pointer to button
window.setTimeout(function() { document.body.style.cursor = '';that.disabled = false; }, 1000);
This approach can be useful to prevent a double-postback too.
Or the update panel finishes it fires the Sys.WebForms.PageRequestManager.endRequest event. Add an event handler to reenable the button in there as another alternative.
In addition to above...
Yes, you are using an UpdatePanel, but a PostBack is occurring.
So, in your submit button event, after successful processing is complete, remove the attribute for onClick you added above, have you tried to enable the button in the code behind and then issue an Update() on your UpdatePanel?

Categories

Resources