when I press the the cancel all changes button, it gives me the confirmation popup twice. I'm not sure where to put my debug statement because the only line of code I am executing in the cancel button function is to clear the EditingOptions
"Cancel all changes" functionality is implemented in PhotoEditorSample. Please, install PhotoEditorSample (it is included into installation package) and review how it works. If you will have some questions - feel free to contact us.
to solve this problem I changed the butShow and butRestore back to regular Button controls. for some reason when I had changed it to a LinkButton control it then showed the message twice, if there is a fix for this that would be great as it allows me greater control of the style of the buttons, but for now I'm just going back to the regular Button controls.
So, when you click the link in IE, IE fires onbeforeunload twice: firstly when meet href="", secondly during execution of __doPostBack.
To eliminate this you may use the following workaround: try to add # into href of A element. This way IE will interprete it as link to part of current page and will not call onbeforeunload event.
To use LinkButtons into your project you should do the following: (I explain getting PhotoEditorSample.ascx as source for changes)
Changes in PhotoEditorSample.ascx: 1. Replace <asp:Button with <asp:LinkButton 2. Remove from <asp:LinkButton ID="butRestore"OnClick property.
Changes in Default.aspx: 1. Change Button to LinkButton into OnInit method.
Changes in PhotoEditorSample.ascx.cs: 1. Add following string to OnInit method:
that worked great! Thanks for the tip as well, it can help in other .NET projects.
one extra thing I needed to do, I needed to move the code for the butRestore_Click event from PhotoEditorSample.ascx.cs to Default.aspx.cs(or my page which is different)
I'm having some trouble with Firefox. It seems that the fix we did in this previous post isn't working for them.
It seems that when you have disabled="disabled" in the html, which doesn't validate, doesn't correspond to the check we're doing in the onclick event (e.g. if(this.disabled) ) for Firefox, I've tried using alert(this.disabled) and it is showing "undefined".
I've even tried to set an add_load method to fix it in script, but it hasn't worked, maybe you can help.
here is what I tried:
//fix for firefox and/or other standards compliant browsers
//if disabled is checked for in script it needs to be set in script
var el = document.getElementById("<%= saveButton.ClientID %>");
if(el)el.disabled=<%= (!saveButton.Enabled).ToString().ToLower() %>;
the result is that I'm getting an error when I click a disabled button in FireFox: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that aruments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
I have reproduced the problem with disabled buttons, so I get the same error when I click on disabled LinkButton. As I understand you have solved this problem for you. But I will post my appreciation in hope that this will be helpful.
All we need is just cancelling click event on disabled elements. So, I have wrapped this elements with div and disabled bubbling of click event if it occurs on disabled element.
To apply my solution you should do the following:
1. Replace in PhotoEditorSample.ascx the following:
// WORKAROUND for disabled elements in IE.
// Using Ms.Ajax we get exception on disabled input element.
// To prevent it we disable bubbling of events.
if (Sys.Browser.agent == Sys.Browser.InternetExplorer) {
butRestore.parentNode.onmouseup =
butRestore.parentNode.onclick = function()
{
if (butShow != window.event.srcElement) {
window.event.cancelBubble = true;
}
};
}
with:
// WORKAROUND for disabled elements in IE.
// Using Ms.Ajax we get exception on disabled input element.
// To prevent it we disable bubbling of events.
if (Sys.Browser.agent == Sys.Browser.InternetExplorer) {
butRestore.parentNode.onmouseup =
butRestore.parentNode.onclick = function()
{
if (((window.event.srcElement == butRestore) && (butRestore.disabled)) ||
((window.event.srcElement == saveButton) && (saveButton.disabled))) {
window.event.cancelBubble = true;
}
};
}
2. Add at the end of PhotoEditorSample.ascx the following.
<script>
Sys.Application.add_load(function(e, t) {
if (t.get_isPartialLoad()) return;
var saveButton = document.getElementById(<% = "\"" + saveButton.ClientID + "\"" %>);
saveButton.disabled = true;
// or
// saveButton.disabled = false;
)};
</script>
3. Change Button to LinkButton in OnInit method in the Default.aspx.cs file.
4. Add the following string in OnInit method in the PhotoEditorSample.ascx.cs file: