I have few questions,
I want to show the alert window on my Update record button click.But
i already i have onClientClick event set for button.So is there
any other way to do that.
Using Response.Write() can i do some thing which is show me
message of updation as well as redirect to my other page.
Can i use ClientScript.RegisterStartupScript methode to do that
functionality? and how
thanks in advance
use OnClientClick and confirm() js
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="return confirm('Are You Sure You Want to Update?')" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="return Validate()" />
<script>
function Validate()
{
//do validation here
if(notPassValidation)
{
alert(validationMessage);
return false;
}
//valifation passed, do confirmation
if(!confirm('Are You Sure You Want to Update?') )
{
return false;
}
else
{
return true;
}
}
</script>
I solved this question by handling the client and server events :)
thanks for all response.
Related
I have the following code:
<asp:Button ID="btnHideDep" runat="server" Text="Remove this institution" CssClass="link1 small" OnClientClick="return confirm('Confirm remove?');" OnClick="btnHideDep_Click"/>
This button does not fire btnHideDep_Click when OK is pressed in the confirm box.
More interestingly, if i have OnClientClick=return true; the method btnHideDep_Click is still not fired. Also just to confirm, without the property OnClientclick, btnHideDep_Click is fired properly.
I read a few posts about this and it seems like this should work. So I must be missing something very basic here...
Try
OnClientClick="if (!confirm('Confirm remove?')) return false;"
I have a page written in asp.net, in which I am calling Javascript alert message and it is not showing up, if I clear cache memory of browser then the alert message is showing up.
Can anybody tell the reason and solution?
Use onClientClick like this
<asp:Button ID="btnSubmit" OnClick="btnSubmit_click()" OnClientClick="return check()"
runat="server"/>
<script type="text/javascript">
function check() {
if (confirm('Are you sure you want to submit ?')) {
// do further form validation here..
return true;
}
else {
return false;
}
}
</script>
How to call javascript function and code behind function using button?
<asp:button id="btnSave" onclick="btnSave();" onclientclick ="return javascriptfunction();" runat="server">
</asp:button>
I tried like this too. but no response.
<asp:button id="btnSave" onclick="btnSave();" onclientclick ="return true;" runat="server">
</asp:button>
even, javascript function return true, its not calling codebehind function. May i know reason?
The code should be something like this -
JavaScript:
<script>
function save()
{
return confirm('Are you sure you want to continue?');
}
</script>
ASPX:
<asp:Button ID="btnSave" OnClick="btnSave_Click" OnClientClick="return save();"
runat="server" />
C# CodeBehind:
protected void btnSave_Click(object sender, EventArgs e)
{
// Do something
}
It basically call JavaScript function before posting back to server. Whether post back to server or not is depending upon the return value from JavaScript function.
Button control's OnClick is an server side event so you need to attach to server side click event.
The best way I have found to do this is from code behind using RegisterStartupScript
ScriptManager.RegisterStartupScript(this, this.GetType(), "name", "javascriptfunction();", true);
I have an ASP.NET form with a cancel button that is supposed to, after confirmation from the user, redirect them to another page. I'm using javascript for this. It works fine in a simple HTML page, but apparently something is interfering with it on the .aspx page. The popup message works perfectly, but clicking "Okay" does not take you to another page. I have tested the if statement and it is working correctly, the only thing it won't do is leave the current page.
My javascript:
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("Are you sure you want to cancel? Any information you have entered will be discarded.")
if (answer) {
window.location = "index.htm";
}
}
-->
</script>
My button:
<asp:Button ID="btnCancel" runat="server" Text="Cancel" onClientClick="return confirmation();" CausesValidation="false" />
Set UseSubmitBehavior property of the button control to false:
<asp:Button UseSubmitBehavior="false" ID="btnCancel" runat="server" Text="Cancel" onClientClick="return confirmation();" CausesValidation="false" />
hi I have an asp button which is created using the following code:
<asp:Button ID="btnBack" OnClientClick='javascript:history.back()' runat="server" Text="back">
</asp:Button>
However, now the javascript doesn't work to go a history back. On the other hand, if I make an alert() it works...why. Why is it not working to go a history back?
Try with return false at end:
<asp:button id="btnBack" runat="server" text="Back"
OnClientClick="JavaScript: window.history.back(1); return false;"></asp:button>
Try:
parent.history.back();
Or
history.go(-1)
Had the same problem in DevExpress project. Using ASPxButton without initializing the property "AutoPostBack" will result in redirect to self page before any client-side function call.
Try AutoPostBack="false" for the button.