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

RadConfirm from GridTemplateColumn on ClientSide

2 Answers 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yash
Top achievements
Rank 1
Yash asked on 28 Mar 2012, 05:14 PM
I have radgrid which I am binding with a Webservice on the client side.

This is what I want to do:
I want to create a GridTemplateColumn or a GridButtonColumn, when clicked should show a RadConfirm and when clicked "YES/OK" on radconfirm should call another javascript function without doing a postback(or page refresh). Other wise should not do anything.

This is what I have done:
Mark up for the grid template column.
<telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn column"
                        UniqueName="DeleteColumn" HeaderText="Delete">
                        <ItemTemplate>
                            <asp:ImageButton ID="btTrash" ImageUrl="/BSS/Admin/resources/Trash.png" runat="server" OnClientClick="DeleteEntry" ></asp:ImageButton>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

Javascript on Row DataBound:
function rgUpdateConfigSummary_OnRowDataBound(sender, args) {
            //var dataItem = args.get_gridDataItem();
            var SiteID = glbl_SiteID;
            var prodID = args.get_dataItem().ProductID;
            var GenID = args.get_dataItem().GenerationID;
 
            var DeleteLink = args.get_item().get_cell("DeleteColumn").getElementsByTagName('input')[0];
 
            var attrib_href = document.createAttribute('href');
           attrib_href.value = '#';
            DeleteLink.setAttributeNode(attrib_href);
 
            DeleteLink.removeAttribute("onclick");
 
            var attrib_onClick = document.createAttribute('onclick');
          attrib_onClick.value = 'showDeleteConfirm(' + prodID + ',' + GenID + ',"' + SiteID + '"); ';
          DeleteLink.setAttributeNode(attrib_onClick);
 
        }

This is the showDeleteConfirm method:
function showDeleteConfirm(prodID, GenID, SiteID) {
            radconfirm('Client radconfirm: Are you sure?', function () { confirmDelete(prodID, GenID, SiteID); }, 330, 100, null, 'Client RadConfirm', imgUrl);
            return false;
        }
 
function confirmDelete(prodID, GenID, SiteID) {
            var service = new tempuri.org.ImyService();
            alert(prodID + GenID + SiteID);
            service.Delete(SiteID, prodID, GenID, rebindandclose);
 
            return false;
        }

But everytime I click on the button, it does a postback without calling the javascript function. Help will be appreciated :)

Thank you.

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 02 Apr 2012, 07:38 AM
Hi Yash,

Could you please try using the following code snippet and let me know if the issue still persists:
function rgUpdateConfigSummary_OnRowDataBound(sender, args) {
                var DeleteLink = args.get_item().get_cell("DeleteColumn").getElementsByTagName('input')[0];
                if (DeleteLink.attachEvent) {
                    DeleteLink.attachEvent('onclick', function () { return showDeleteConfirm(prodID, GenID, SiteID); });
                } else {
                    DeleteLink.setAttribute('onclick', 'return showDeleteConfirm(' + prodID + ',' + GenID + ',"' + SiteID + '"); ');
                }
 
            }

Looking forward for your reply.

Kind regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Apr 2012, 08:00 AM
Tags
Grid
Asked by
Yash
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Jayesh Goyani
Top achievements
Rank 2
Share this question
or