I have an aspx page on my SharePoint site, which I have included tags. For some reason, every button on the page will reload the page when clicked. Even the buttons with no attributes (id, class, etc) or functions will reload the page when clicked. How can I fix this issue? I can't even see what's going on in the debugger because I'm not calling any reload functions, so I have no idea where to place a breakpoint.
Thank you in advance for your help, I really appreciate it.
The problem here is with the <button> tag. Its default behavior is to act as a submit button unless otherwise declared and will reload.
To keep your <button> tag, add type='button' to the button element. I think that prevents the reload.
Or you could go with the ole <input> tag with a type='button'. That keeps the reload from happening as well.
Or some other html element with an onclick event will work too.
First search for a function called doPostback and set a breakpoint on the entry point and click a button. If you hit this breakpoint it could mean that auto post back is turned on for the control generating the button. However if you trigger that breakpoint you should be able to look at the stack trace to figure out how you got there.
If that doesn't work, use the F12 tools in the browser, start with the HTML section and search (Ctrl-F) for the word "click". Then go to the script tab and do the same for each JavaScript file. If all of the buttons exhibit the behavior there is most likely a click event registered. Possibly with jQuery that looks like this $('button') so that it matches all buttons on the page and registers a click handler.
If that doesn't find it, and you have access download one of the master pages from http://startermasterpages.codeplex.com/ and temporarily replace your master page with one of these. Take a screenshot of the scripts that are loading on your page first. Then add them to the starter master page one at a time until the unwanted behavior returns. Then set a breakpoint on every function entry point in that script and click a button and see where you land.
Related
I have a page with few forms in it and a submit button to save the records. If there is any errors then I m displaying the error messages programmatically in faces message .
But after clicking on the ok button on the af message, the page scrolls to the top and I have to scroll down again to click the button.
Is there any way to save the scroll position in ADF . I tried to call Java script
Window.scrollto () method
But for other methods it's working fine but not after clicking on the af message ok button.
Please let me know any way to scroll down to the bottom of the page.
markosca already gave the correct hints as a comment.
I'll clarify a bit on this for the sake of a complete answer:
If your buttons trigger an action, always a complete new site will be loaded.
Even if the "new" site is equal to the old one, it will seem as if the site has scrolled up.
If your buttons have an actionListener registered, this scrolling will also happen. Even if you put an addPartialTarget(...) inside that registered Java-method.
So, how to solve this? It's easy, just use an actionListener and the attribute partialSubmit="true" on the button or link.
Only than a partial submit will be executed instead of a full page reload.
And don't forget to either use addPartialTarget(...) in Java or the attribute partialTriggers="..." on the components which should update because of that partial submit.
I Have a chrome extension, it click a button when the page is loaded.
$(document).ready(function(){
document.querySelectorAll("input[type='submit']")[0].click();
});
This works, the only problem is that the button is also on the next page. So it keeps pressing the button and the page keeps reloading, so it's in a loop.
How do I fix this?
One solution would be to refine your selector. Find an unique parent element for the page you're targeting and create a more specific selector.
Another solution would be to check the current page url or the referrer and see if it matches a certain pattern.
I have the following code in an MVC view that I'm using to test window.history.back()
If the user clicks the link (highlighted in red) within the paragraph tag, window.history.back() executes as I would expect. It takes me back to the prior page with state maintained on that page. However, if the user clicks the button, I don't get the same behavior. The current view is reloaded, or at least an attempt is made to reload the current page. But it fails. And it doesn't matter if the jQuery is executed, or I put the window.history.back() call within the Button onClick, the same thing happens.
A piece of information which might be helpful. The button is inside an HTML.BeginForm and the line in the paragraph tag is not.
Anyone know why this is happening?
The browser is probably interpreting the button as a submit button and submitting the form, thus causing a page refresh. Adding type="button" will prevent that.
<button type="button">Cancel</button>
$('#cancelButton').click(function(e){
e.preventDefault();
/* ... code ... */
});
I have a page that uses JQuery UI Tabs and some other bits and pieces. When a user opens this page and quickly clicks on some tab, after a second or so the page reverts to the first tab again!
I am trying to use Firebug to see what's going on, but as far as I can see, when that reversion occurs the body tag highlights, but nothing within it. I am a novice with Firebug - how can I use it to better understand what's going on here?
I can only take a guess without a concrete example, but it sounds you're initialising the tabs twice. The tabs must already be enabled which is allowing the initial navigation between tabs. Then a second initialisation of the tabs is resetting the view back to the first tab.
You are initialising the tabs inside $(document).ready and not window.onload, right?
I am trying to see witch one i like best, Tiny MCE or CKEditor. The problem that i am getting is that i need to add a custom toolbar button (or extend the anchor button). Trying now to modify the advlink plugin to insert internal links from the CMS. So i modified the page link.htm and added one button next to the href field. This button opens up a small popup where the user can select an internal link in the CMS and then press insert. The small popup then uses javascript to send the result back to the link.htm page. The link is then inserted into the href field. My problem is that when i press insert on the link.htm page, it just reloads the page and nothing is inserted.
This is the javascript that i added to the link.htm page:
function ShowInternalLinks() {
window.open('InternalLink.aspx', 'InternalLink', 'toolbar=0,status=0,menubar=0,location=0,directories=0,resizable=0,scrollbar=0,width=400,height=200');
}
function InsertInternalLink(link) {
document.getElementById('href').value = '/1/?' + link;
}
Nothing fancy, just opens up my custom aspx page when the ShowInternalLink is clicked. Then when the user clicks on insert on that page, the page calls the javascript InsertInternalLink and then closes the small popup. Everything works when i run the page, the href gets the correct value from the popup page, but when i then press insert, the page just reloads and the href field resets itself.
Any ideas? (If i write in the URL in the href field, it works perfectly. Just doesn't work when i use my popup window)
Side question: Can this even be done easily in CKEditor?
The href field has an onchange listener that performs the following: selectByValue(this.form,'linklisthref',this.value);
Can you debug and see if this is being called. I'm thinking that it isn't, and this might be your problem.