History.go(-1) not working in IE - javascript

I have a go back button and i have used the following piece of code in my aspx page
<input type="button" runat="server" value="Back" onclick="Javascript:history.go(-1); return=false;" />
The prob is its working fine in Firefox but when i am trying it in IE its not working. Can someone share their Idea.
Update
By mistake I write return=false; the actually code is:
<input type="button" runat="server" value="Back" onclick="Javascript:history.go(-1); return false;" /> and still not working.

Your quoted code shouldn't be working on any browser, it has a syntax error (return=false). With minimal changes:
<input type="button" runat="server" value="Back" onclick="history.go(-1); return false;" />
Also note that you don't need (and shouldn't have) any Javascript: prefix on any onXyz attribute. The code in onXyz attributes is always JavaScript, and in fact that prefix (in that situation) doesn't trigger JavaScript, it creates a label that's never used. You use the javascript: pseudo-protocol in places where a link is expected, such as the href attribute on an a element.
Side note: I haven't done any ASP.Net in a long time, I'm not at all sure it makes sense to have runat=server and onclick on the same input... If you want a client-side "Back" button, remove runat=server.

Use Back
or
<input type="button" runat="server" value="Back" onclick="history.go(-1); return false;" />
After any on... events you need no javascript, you need it only at href.
And at the return you need no =.

Related

ASP.NET Page does not contain a definition for Javascript method

I have a javascript handler method for giving a confirmation if page unloads.
<script language="javascript" type="text/javascript">
function handler(form)
{
confirm("are u sure?");
}
</script>
And I have used it here
<asp:Button ID="CreateTestButton" runat="server" Text="Submit" class="btn btn-default" OnUnload="handler(this)"
OnClick="CreateTestButton_Click"/>
Thanks for the help!
OnUnload is a server side event. It is called when the control unloads from memory on the server. You can't use it to call a JavaScript function.
I think your misunderstanding comes from the difference between server side and client side. In web frameworks, your server side code executes first and renders HTML (along with CSS and JavaScript). That's all sent to the client where it is then executed in the browser.
If you want to have the user confirm before they navigate away from the page, you need to add an event handler from the appropriate event on the client side. Like this:
window.onbeforeunload = function() {
// Do something
}
See this question for more detail.
Keep in mind that you should not abuse this capability by asking them on every page. You typically only do this if there is important page state, such as the user has partially filled out a form.
Well, may be you can do something like below,
<form action="YourPageName.aspx" method="post">
<input name="TextBox1" type="text" value="" id="TextBox1" />
<input name="TextBox2" type="password" id="TextBox2" />
<input type="submit" name="Button1" value="Button" id="Button1" />
</form>

How to get window.print() to run locallly?

Hi I have been writing a website for the last couple of weeks but cannot get the Javascript function window.print() to run locally in my browser. I do not have server space yet so I cannot check the online functionality. Here is my code:
<form>
<input type="button" value="Print this page" onclick="window.print();" />
</form>
Does anyone know if this function can run on a local machine? Or is there a problem with my code? Thanks
The syntax is fine. It should work.
You might also want to try onclick="javascript:window.print();" and see if that works.
Another option you can try then is to create a function inside a script tag and call it from your onclick event:
<input type="button" value="Print this page" onclick="PrintMe()" />
<script>
function PrintMe(){
window.print();
}
</script>
It might be a problem with the form tag..
try using button without form requirement
<button onclick="window.print();">Print this page</button>
Or if you are using the form
<form>
<input type="button" value="Print this page" onclick="window.print();return false;" />
</form>
if alert works and then enables this to work what happens if you try
onclick="console.log(window.print());return false;"
Capitilize the C in onClick. That might help. That's how I learned it, anyway.

How to disable link button after click (no JQuery)

I want to disable link button after user click on it.
But I made something wrong here.
Button is still enabled after click. What am I doing wrong?
<asp:LinkButton ID="submit" runat="server"
CssClass="button"
Text="OK"
OnClick="Submit_Click"
OnClientClick="this.disabled=true">
</asp:LinkButton>
Just give return false; to your JavaScript. The reason is that your asp:LinkButton is getting rendered like this.
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$submit','')"
class="button"
id="ContentPlaceHolder1_submit"
onclick="this.disabled = true;return false;">
OK</a>
So, if you do not give return false, these things happens
It fires the onclick event and disables the anchor tag. (anchor tag does not have a disabled property. button and input type="submit" has that property.)
It moves on to fire the postback and hits the server side click event
As there is a postback, the client side JavaScript disabling wont persist (even if it were a button)
By enforcing return false you are asking the asp:LinkButton not to do anymore processing.
P.S: I have been using PostBack Ritalin to prevent multiple clicks on asp:Button. IMO, its definitely worth a look in this case.
Use the javascript debugger to check the method is being called. LinkButtons are server generated javascript powered anchor tags & therefore can be tricky.
Try this java script function ,
On your OnClientClick
<asp:LinkButton ID="submit" CssClass="button" Text="OK" onclick="myButtonId_Click(this);return false;" ></asp:LinkButton>
add function ,
protected void myButtonId_Click(target) {
target.disabled = true;
}

More submit button disabling on click with Jquery, doesn't work

I got this code here:
It works fine as far as disabling and replacing the Submit button goes, but it will not submit the form. My form uses the 'get' method and submits data to another page.
<script type="text/JavaScript">
$('.button').click(function() {
$('.button').remove();
$('.holder').append("DONT DOUBLE CLICK ANYTHING IN A BROWSER");
$('.form').submit();
});
</script>
I have tried most things, including changing .form to the id of my form, still no joy, any ideas would be helpful.
HTML code
<form action="liftingConfirm.asp" method="get" id="frmArchiveConfirm">
<input name="con_id" type="hidden" id="con_id" value="<%=request.querystring("con_id")%>" />
<input name="sub_id" type="hidden" id="sub_id" value="1" />
<input name="liftingDate" type="hidden" id="liftingDate" value="<%=Session("currentUSDate")%>" />
<div class="holder"><input name="btnConfirm" type="submit" class="button" id="btnConfirm" value="Start New Lifting Gear Examination" /></div>
You're using the wrong selector, the .form is looking for a <form> with a class of form. Furthermore you should be using the on() syntax:
$('form').on('click', '.button', function() {
$('.holder').append("DONT DOUBLE CLICK ANYTHING IN A BROWSER");
$('#frmArchiveConfirm').submit();
$('.button').remove();
});
For your jQuery code to work you should include the frmArchiveConfirm to your jQuery code as below.
Replace $('.form').submit(); with $('#frmArchiveConfirm').submit();
else if you only having one form in the page just use $('form').submit();
When you come across bug like this don't forget to make use of the firebug or the browser development tools. You can easily figure out the bug and what's wrong in your code.

How to first use javascript to validate form data before triggering onServerClick for HTML Input button?

So right now it all looks pretty with ...
<button type="submit" runat="server" name="subscribe" id="Button1" class="link-button" onserverclick="saveListing">
Until it is time to validate the data before calling saveListing function codebehind (in VB .Net).
How can true/false be return so that when true saveListing will be called, otherwise not?
Thank you.
add onclick='if(! validateFunction()) return false;.
I can't recall correctly whether HTML button control had onclicentclick property. Surely, if the web control <asp:Button ... it has a property OnClientClick where you can give the same value above for this effect as well.

Categories

Resources