window.close() to restrict parent page to refresh - c#

I have opened a dialog box using jQuery. In dialog box I have added to code to close when close button is clicked. In this function i have used window.close(). In some cases it refreshes the parent page but i do not want to refresh the parent/caller page. How can I restrict parent page to refresh.
if (condition)
{
window.close();
return false;
}
Thanks.

event.stopPropagation() of jquery Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.Is this what you were looking for?.Hope that helps.

Related

Fancybox does not recreate the source element after postback and trigger click

When triggering a fancybox click event with RegisterStartupScript after postback, the source element does not get recreated when closing the fancybox.
The user opens up the fancybox with a form and submit button as content.
The user is able to open and close the fancybox multiple times as expected if not posting the form.
When the user hits the submit button a fancybox trigger click scripts gets injected with RegisterStartupScript in order to show the form with a confirmation message directly after the form has successfully been sent. This works as expected.
If the user then clicks the close button of the fancybox the source element is not recreated to it's original position in the DOM. So if the user tries to open the fancybox again the content is missing and the fancybox breaks.
I expect the source element to be recreated when closing the fancybox.
Example of code:
// Form submit button
FormSubmit.Command += new CommandEventHandler(submit_command);
// Click event
protected void submit_command(object sender, CommandEventArgs e)
{
// Do stuff
// Trigger click event on fancybox in order to reopen the form immediately after postback
Page page = HttpContext.Current.Handler as Page;
ScriptManager.RegisterStartupScript(page, page.GetType(), "reopen", "$('#OpenFancy').fancybox().trigger('click');", true);
}
So the fancybox is reopened as expected but when I close the fancybox and try to open it again the fancybox breaks because the source element has not been copied back to the default position in the DOM.

Bootstrap - open modal after postback only after button click c#

I have just implemented a modal popup on my site to capture email addresses. Once the user clicks the submit button the form is submitted. I am calling the modal again after a page.ispostback which works fine. However, I only want it to display after a user clicks that particular submit button. As this is on a master page, if someone goes to my 'Contact Us' page and submits a question on postback the modal reappears which I don't want. I literally only want it to appear after a postback from the submit form on the modal.
Any ideas how I can get around this?
Thanks
Rob
To display the modal only after the user clicks the submit button, you should put the modal's display logic only in this button's submit event.
Take the logic out of the Page_Load's IsPostBack, and put it at the end of this button's OnClick event
protected void Button_Click(object sender, EventArgs e)
{
// Do some work...
// Show modal
}

Update the grid when using registration form (WebUserControl) open in apopup

i have a grid view on a page and i have webusercontrol which contains the registration for and this usercontrol open in a popup and when i click finish submit of registration this will add the new entry in database. but my grid still show previos records untill i refresh the page . so how can i rebind the grid on click of Submit button of user control?
thanks
You need to refresh parent page on popup window closing.
This link would be help. Closing-child-pop-up-and-refreshing-parent-page
Or you can check the javascript code below.
function refreshParent() {
window.opener.location.href = window.opener.location.href;
if (window.opener.progressWindow)
{
window.opener.progressWindow.close()
}
window.close();
}

ASP.NET - How to track event from previous postback?

I have a requirement to check for a certain condition on postback before redirecting (Response.Redirect) to another page.
Note... I cannot use JavaScript to detect whether or not to confirm (this is also a requirement) :s
Pseudo:
protected void lbtnRedirect_OnClick(object sender, EventArgs e)
{
if (showConfirm)
{
// Set flag for client side
this.ShowConfirm = true;
// Track this event for next postback.
}
else
{
Response.Redirect("somepage.aspx");
}
}
If the showConfrim flag == true, then the client will be show a modal dialog box asking them if they are sure they want to redirect. If the user clicks on "Yes", then the page posts back and the desired effect is that the lbtnRedirect_OnClick event is fired. How would I about tracking the lbtnRedirect event?
Edit:
I have no problem tracking the flag to show the modal (yes JS must be used to show the modal... somethings you just cannot get rid of :)). I should have been more clear.
It is when the user clicks "Yes" to continue the redirect. The page will postback again but needs to know which event to go through.
i.e. Suppose there are 3 onclick events, 1) lbtnRedirect1_Onclick 2) lbtnRedirect2_OnClick 3) lbtnRedirect3_OnClick... each of which does the confirm check.
Each onclick event does the check. So when the user clicks on "Yes" on the modal, how does the page know which event to drop back into?
You can use ViewState if you're in WebForms.
Implement a ShowConfirm property encapsulating ViewState["ShowConfirm"].
In the first postback you'll set ShowConfirm 'true', and this will activate that modal during the render (if ShowConfirm is true, that's setting as visible 'true' some control).
In the next postback, you'll set ShowConfirm 'false' because is 'true', and finally you'll do the whole redirect!
You can use an ajax call from javascript to set the required values.
Since the postback will happen before even the execution reaches to your button click event we need a workaround here, And if you don't need JS as your requirement, so take a look at
Implementing Client Callbacks Programmatically without Postbacks in ASP.NET
This is much like a wrapper for XMLHttp Ajax call IMHO.
You cannot easily create a model form, without javascipt.
One suggestion I would make is to have panels in your page.
Panel one is visible.
On submit one; panel one hides and panel two is visible asking for a confirmation.
On panel two is a confirm button, clicking this button your redirection is performed.

DataList ItemCreated event

I have a datalist in my aspx page. In the datalist, there are images displayed. When I click on an image, a bigger version of the image appears in a popup, and in this popup there is a button. On that button, I want to react to a click even without postback. What I'm doing now is not working every time. I am using go for the item_created event and __dopostback(btn.id,"onClick").
The item_created event fires when I click on the ok button on the div that displays the image.
If you mean that ItemCreated event is firing every time post back is occurring. Please do your databinding only first time when page loads. You can use IsPostBack property to check if it is a postback or fresh loading of page.
Page_Load(....){
if(!IsPostBack){
LoadData();
}
}
If you do not want to use postback on button click, please use ajax and page methods. You can get more information here: Using jQuery AJAX to directly call page methods.

Categories