Friday, February 11, 2011

ASP.Net Button’s OnClientClick event

There are occasions that we need to check whether the fields in the page have been filled before executing the button clicks. You can use required field validators for this. Also you can use the above mentioned function of the button.

This can call a custom javascript function which you can write and depending on the value that you get from the function you can determine whether to proceed or not. An example of this is given below. In this example we are checking the length of the text entered to a field.

<asp:Button ID="cancelButton" runat="server"  onclick="cancelButton_Click" Text="Cancel" Width="160" OnClientClick="return confirmationOfCancellation()"  />

function confirmationOfCancellation() {

var field = document.getElementById('cancellationReasonTextBox');
if (field.value.length > 0) {
if (!confirm(‘Proceed’)) {
                    return false;
                return true;
            else {
                alert(‘You will not proceed’);
                return false;

No comments:

Post a Comment

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...