Display a alert box in ASP.net c# web application - c#

I want to display a alert message when a user clicks on button.
I have a button "Signed" on click of this button I want to display a alert message saying "Are you sure you want to continue?" and two buttons in this alert message box "Yes" and "No".
On click of yes button I want a update function to be executed and on click of "No" only Alert should get closed and no changes in the current page.
Please anyone can guide me how to go on with this?

You can use the OnClientClick on the button for this.
Add a return confirm(); to it. It will create a javascript confirm dialog, BEFORE it fires the click event.
If the user presses no, it will not trigger the OnClick event.
OnClientClick="return confirm('Are you sure you want to continue?');"
So, added to your button markup, it would look like this:
<asp:Button ID="Button5" runat="server" Text="Signed" Visible="False" onclick="Button5_Click" OnClientClick="return confirm('Are you sure you want to continue?');" />

jquery should do for you.
$("#ButtonId").click({
return confirm("Are you sure you want to continue");
})

Related

Triggering AjaxControlToolkit ModalPopupExtender Cancel Control

My ModalPopupExtender has:
CancelControlID="btnClose"
<asp:Button ID="btnClose" runat="server" Text="Close" Width="50px" />
btnClose can not have an OnClick event. System simply does not work if it does.
My popup form has 3 other buttons, Save. Delete and Cancel.
If any of these are used, the Wizard Next button and the Sidebar Links no longer work. They only work if btnClose is used. I assume it does something to tell the system the popup is closed. How do I make my Save / Delete / Cancel buttons do the same thing? cam I trigger a btnClose.Click?
you can close ModelPopupExtender from code behind as well as from java script based up on your requirements.
C#:
ModalPopupExtender1.Hide();
Javascript:
$find('ModalPopupExtender1').hide(); //keep this in a function an call the same function where ever you want

To stop reloading web page In Asp.net on any button click

how stop postback on any button click. My page is reloading as soon as i click on reset button on the registration page, i want to reset the form without reloading the page itself.
You have two possibilities:
Simply set the attribute AutoPostBack="false" on your button or whatever control.
As an alternative you could also add the following javascript to the click event of the button :
onclick="return false"
This prevents the button from submitting.
Try following:
<asp:button runat="server".... OnClientClick="return false;" />
First you have to know about Sever Control and normal HTML control.
If you used Server Button Control then your Page reload on each click.
If you wan to stop it then you have to use AutoPostBack="false", using this your server side method calling is stop.
Otherwise use Normal HTML Button Control and use JavaScript to reset your form.

Message box cant be displayed When run in IIS?

I wants to display an OK/CANCEL message box. I have written like this.
if (MessageBox.Show("Are you sure you wants to Save the details ? ", "Validate", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
// do something if "OK "
}
it works locally well.. but on IIS shows an error " Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application."
please help.
To get the effect I believe you are wanting, you'll want to use the Javascript confirm() function. It is typically used like this:
<asp:Button runat="server" OnClientClick="return confirm('Are you sure you want to save the details?')" id="btnSubmit" OnClick="btnSubmit_Click" />
This would, upon clicking the button, display a confirmation box that would stop the server OnClick event from firing if the user clicks No, Cancel, etc.
OnClientClick will render as an onclick event on the <input> tag. The rest is determined by the browser's handling of Javascript. See What's the effect of adding 'return false' to a click event listener? for more details on what the return value of the code in OnClick (OnClientClick) does.
Here's an example of the return values of confirm() using Chrome. For the first execution I had clicked Cancel.

writing a jquery message-box and join it to server-side handler

I need some jquery code in my application I have a button on the page and I want to handle it by jquery when the user click on it to show a confirmation dialog for example Are you sure? yes|no buttons but this is an asp.net button inside the updatepanel and in the other side I have some server side code to delete a record from database but my question is how I can handle both of them? server side and jquery inorder to when "yes" button clicked it runs server side and delete recorde from database and if the button is no it stop running ?
you need to use confirm javascript function
<asp:button id="fooBtn" runat="server" OnClientClick="return confirm("Are you sure?") />
Here is a link to confirm function.

ModalPopup inside the UpdatePanel with default form values

I have a ModalPopupExtender inside an UpdatePanel which opens an input form. The problem is when I click the "Edit" button (which is also inside the UpdatePanel) I want to fill the form with existing values using server side code. But it OnClick method of the button doesn't seem to work.
My question is: How can I make the serverside code run first, than show the edit form?
You need to show the ModalPopupExtender from server side.
First, link the ModalPopupExtender's TargetControlID to a dummy hiddenfield or a button with style="display:none" instead of the "Edit" button. I know it's sound stupid, but it's a know workaround.
Then make sure the asp.net the "Edit" button is set as a asyncpostbacktrigger if children as trigger is set to false.
Also set CausesValidation="false" to avoid the postback to be blocked by unrelated validators on the page.
Finally, At the end of "Edit" button's click event, call ModalPopupExtender.Show() to display the pop up.

Categories

Resources