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

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.

Related

C# WebBrowser button addtocart Click it , then go to the next another page and click submit

i used this to click in the first page
webBrowser1.Document.GetElementById("vwd-add-to-cart").InvokeMember("click");
and i want to click in submit button in the next page
after the previous completely loaded.
webBrowser1.Document.GetElementById("shipping-first-name").SetAttribute("value", "john");
after clicking in addtocart button and the page loaded i want to put this in first name
how I will know that I am in the next page after clicked on the first page and start put code in the next pageenter image description here??
here you can see gif pic to understand
enter image description here
You should register an event DocumentCompleted
WebBrowser.DocumentCompleted Event
webBrowser1.DocumentCompleted +=
new WebBrowserDocumentCompletedEventHandler(webDocument);
private void webDocument(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
// this will raise after your page loaded.
}

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
}

window.close() to restrict parent page to refresh

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.

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();
}

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