This is a migrated thread and some comments may be shown as answers.

Detect Cancel Button click

1 Answer 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 11 Jan 2011, 04:06 PM
Hello In my radgrid one edit form .. i will update some values.. I handle some java script code for validation
Their one textbox UPC .. if UPC code is not valid it will show alert message.. after showing alert message when i tried to click on cancel. It will again and again warn me "Invalide UPC".. it's not handle cancel button click.

Code for UPC textbox

javascript
function validateUPC(txtUPC) {
        debugger;
        var txtboxUPC = document.getElementById(txtUPC);
        if (txtboxUPC.value.length != 12) {
            alert('Invalid UPC Barcode');
            txtboxUPC.focus();
            return false;
        }

        if (!validateUPCCode(txtboxUPC.value)) {
            alert('Invalid UPC Barcode');
            txtboxUPC.focus();
            return false;
        }

code behind cs file  to call javascript on textbox onblur
TextBox txtGameUPC = (TextBox)editForm.FindControl("txtGameUPC");
               txtGameUPC.Visible = true;
               txtGameUPC.Enabled = false;
               //Call Java script function to validate the UPC code
               txtGameUPC.Attributes.Add("onblur", "validateUPC('" + txtGameUPC.ClientID + "');");


On cancel button click
javascript
function RaiseCancel(sender, args) {
        if (args.get_commandName() == "CancelUpdate")//check for the condition
        {
            //your code here
        }
    }

<ClientSettings>
                    <ClientEvents OnCommand="RaiseCancel" />
                </ClientSettings>
It's does not raise event cancel. I don't know why this is happen ...

Help me urgent

plz find attach file u get an idea

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 14 Jan 2011, 07:33 AM
Hello rahul,

The easiest way is to find the button in code-behind in the ItemDataBound event and attach a client-side event handler to it.

protected void Page_Init(object sender, EventArgs e)
{
    RadGrid1.ItemDataBound += new GridItemEventHandler(RadGrid1_ItemDataBound);
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        ((LinkButton)e.Item.FindControl("CancelButton")).Attributes.Add("onclick", "javascript:return RaiseCancel()");
    }
}

Hope it helps.

Greetings,
Tsvetoslav
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Rahul
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or