Dynamically set ConfirmText on GridButtonColumn

26 posts, 0 answers
  1. Tom
    Tom avatar
    41 posts
    Member since:
    Feb 2009

    Posted 12 Jul 2010 Link to this post

    Hello,

    I have a RadGrid with a GridButtonColumn.  I have messages in a table in my database that I want to display instead of hard-coding the message in the ConfirmText property in the designer.  How do I go about setting the ConfirmText property dynamically?

    I attempted to find the GridButtonColumn in the OnItemDataBound event, but received a message that a control cannot be cast as a GridButtonColumn.

    Thanks,
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 12 Jul 2010 Link to this post

    Hello Tom,

    You can do so in the OnPreRender event of the Page as follows (beforehand, you need to set the UniqueName property of the column):

    protected override void OnPreRender(EventArgs e) 
        base.OnPreRender(e); 
        ((GridButtonColumn)RadGrid1.MasterTableView.GetColumnSafe("YourColumnUniqueName")).ConfirmText = "your confirm dialogue text."
    }

    Hope it helps.

    All the best,
    Tsvetoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tom
    Tom avatar
    41 posts
    Member since:
    Feb 2009

    Posted 12 Jul 2010 Link to this post

    Tsvetoslav,

    Thanks for the quick reply.  I implemented the page OnPreRender event as shown, but there is no popup now (as compared to using the ConfirmText in the designer of the radgrid).  Do you have any ideas on why I am not seeing the popup?

    Thanks,
  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 14 Jul 2010 Link to this post

    Hi Tom,

    Attached is a small sample that should give you more information.

    All the best,
    Tsvetoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 25 Jan 2011 Link to this post

    Hello Tsvetoslav,
    If I'm correct what you suggest does set the same text for all the buttons...

    But what I need is to set custom text for each button.

    Right now I'm using the following which is working how I want, just I want to use radwindow instead of the standard web browser dialog:
    protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem dataItem = e.Item as GridDataItem;
                    string contactName = dataItem["Nom"].Text;
     
                    ImageButton button = dataItem["colDelete"].Controls[0] as ImageButton;
                    button.Attributes["onclick"] = "return confirm('Etes vous sur de vouloir suprimer le stagiaire \"" +
                    contactName + "\" ?')";
                }
            }

    It would be really nice if I could set the confirmtext to:
    ConfirmText="Suppress the student with name: {0}?" and tell somewhere else that it should use the value from a given field... That way I would have nothing to do ;)

    Any idea? Thanks a lot in advance,
    John.

  7. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 31 Jan 2011 Link to this post

    Hi John,

    Your approach is correct and valid. If you need to display a RadWindow confirm dialogue, you need to place a RadWindowManager control on the page - sorry for having missed this detail in my sample.

    Do let us know if you need further assistance.

    Regards,
    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.
  8. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 31 Jan 2011 Link to this post

    Hello...
    Thank you for your help but I'm not sure to get you...

    Let me rephrase my problem...

    I have a grid with a column to let me delete entries in my grid.

    Before deleting something, I want a RadWindow to confirm my deletion.

    I'm using this to achieve my goal:
    <telerik:GridButtonColumn ConfirmText="Delete that entry?" ConfirmDialogType="RadWindow"  HeaderStyle-Width="30px" ConfirmTitle="Sure?" ButtonType="ImageButton" ImageUrl="Images/ok.png" CommandName="Delete" Text="Delete the entry" UniqueName="colDelete" />

    The problem is that I want to customize the text so that I can include the name of the item that I want to delete.

    Instead of displaying "Delete that entry?" I want to display "Delete entry 'John' "...

    How can I do that with a telerik:GridButtonColumn and a RadWindow?

    dataItem["colDelete"] gives me a GridTableCell.

    dataItem["colValider"].Controls[0] gives me an ImageButton...

    How can I access to the ConfirmText of the current row to be able to customize it...

    Thank you for you help,
    John.

  9. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 31 Jan 2011 Link to this post

    Hello John,

    Please take a look at the following forum which also discusses the similar scenario. Hope it will help.
    GridButtonColumn, RadWindow and ConfirmText

    -Shinu.
  10. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 31 Jan 2011 Link to this post

    Hello shinu,
    Thanks you for your help.
    You are right, that should work but I prefer a server side solution.

    I'm sure there must be a way to access to that ConfirmText property...

    Anyone ?

    Thanks again,
    John.
  11. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Feb 2011 Link to this post

    Hello John,

    Try the following code snippet to achieve this.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
               GridDataItem dataItem = e.Item as GridDataItem;
                string contactName = dataItem["Nom"].Text;
                (RadGrid1.MasterTableView.GetColumn("colDelete") as GridButtonColumn).ConfirmText = "Delete    "+contactName;
             }
        }

    Thanks,
    Princy.
  12. Stephen
    Stephen avatar
    158 posts
    Member since:
    Jan 2009

    Posted 10 Feb 2011 Link to this post

    When I use the code below and change the ConfirmText in the ItemDataBound, it is setting it for the next row, not the current row.  Is there a bug or am I doing something wrong?
  13. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 11 Feb 2011 Link to this post

    Hello Stephen,

    I tested the code slice provided by Princy and it worked as expected - the confirm text is set for the button in the same row since the same GridDataItem (e.Item) is referenced. I suggest you debug your code to trace the code execution, this can help idenfity the cause of the abnormality to eliminate it.
     
    Kind regards,
    Sebastian
    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.
  14. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 11 Feb 2011 Link to this post

    Hello Sebastian,

    I have to agree with Stephen, the number is off one row...

    I would be interested in seeing your working sample.

    Let me explain what I understand from the tips suggested by Princy (thanks Princy by the way for helping out here and there;) )
    correct me if I'm wrong.

    This 
    (RadGrid1.MasterTableView.GetColumn("colDelete") as GridButtonColumn).ConfirmText = "Delete    "+contactName;
    gives me access to the column, not to the current controls in the current row cell...

    Also we are in the _ItemDataBound event.

    So my gessing is that setting the ConfirmText here comes to late in the grid rendering to be used correctly for the delete button.

    That's why it's only used in the next row.

    I tried in _ItemCreated but it's not working either.

    The hint that proves my theory is that the first line of the grid has an empty ConfirmText and all the other lines are of by one line...

    Now, I may be wrong... in my sample, I have to columns to help test my delete scenario :
    //build custom delete message
    string contactName = dataItem["SessionID"].Text;
     // using standard javascript
    ImageButton btnDelete = dataItem["colDelete"].Controls[0] as ImageButton;
    btnDelete.Attributes["onclick"] = "return confirm('Etes vous sur de vouloir suprimer la session N° : " +
    contactName + " ?')";
     //using the radwindow
    GridButtonColumn btnOldDelete = RadGrid1.MasterTableView.GetColumn("oldDelete") as GridButtonColumn;
    btnOldDelete.ConfirmText = "Etes vous sur de vouloir suprimer la session N° : " + contactName;

    The first version does display the correct text, the second is one row off...

    Anyway,
    Thank you for your help guys, what do you think?
    John.
  15. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 14 Feb 2011 Link to this post

    Hi guys,

    Indeed John is right - please excuse me if my previous response was misleading for you. I actually tested the code setting onclick attribute for the button inside the GridDataItem as John posted previously in this thread. This is the proper means to invoke a confirm dialog and set its text on a per-row basis (obtaining cell text value from the same row).

    Using the ConfirmText property of the GridButtonColumn is applicable for specifying a common (row context independent) confirm text for each of the buttons in that column.

    Kind regards,
    Sebastian
    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.
  16. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 14 Feb 2011 Link to this post

    Hello Sebastian,
    Sorry to insist...
    But the interest in using the ConfirmText property of the GridButtonColumn is that this uses a RadWindow whereas the other way is using the default browser dialog. And what I want to use it the RadWindow to ask confirmation...
    Is there something that can be done for that?
    Use a RadWindow with custom text for each row of my grid?
    This would be really nice because as you probably know, the dialogs in IE make a noisy bit and this is a real pain for my users...
    Thanks yo for your help,
    John.  
  17. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 14 Feb 2011 Link to this post

    Hello John,

    I see your point here. If you prefer to use RadWindow for confirm dialog on a per-row basis, consider the implementation presented in this KB article.

    Best regards,
    Sebastian
    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.
  18. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 14 Feb 2011 Link to this post

    Hum I see...
    This all seems like overkill for such a simple task.
    Too bad since all we need is there, just we don't have access to it...

    Would you consider adding the following feature to your framework by allowing the following syntax for the GridButtonColum?

    <telerik:GridButtonColumn ConfirmText="Delete entry '{0}'?" Field="Name"
    ConfirmDialogType="RadWindow"  ConfirmTitle="Sure?" CommandName="Delete" UniqueName="colDelete" />

    So that you would automaticaly insert the row field Name in place of the {0}?
    This would solve the problem very easily at the column level.

    What do you think?
    John.
  19. Marin
    Admin
    Marin avatar
    1044 posts

    Posted 17 Feb 2011 Link to this post

    Hello John,

    Thank you for the suggestion.

    We will do our best to implement this feature for the next major release of RadControls.

    Best wishes,
    Marin
    the Telerik team
  20. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 17 Feb 2011 Link to this post

    Good to hear... thanks.

    But until then? What can I do?

    Is the only way to it (have custom text with radwindow), to use the solution suggested by Shinu here?
    http://www.telerik.com/community/forums/aspnet-ajax/grid/gridbuttoncolumn-radwindow-and-confirmtext.aspx

    -John
  21. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 18 Feb 2011 Link to this post

    Hello John,

    Yes, the current options you have are described in this thread. Note that the next major release (Q1 2011) of our AJAX suite is scheduled in the middle of March and a Beta version of it is expected to roll out at the end of the next week.

    Greetings,
    Sebastian
    the Telerik team
  22. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 18 Feb 2011 Link to this post

    Great. I'll keep an eye on it and make sure to test and use the featue when it comes out.
    Thanks for your help,
    John.
  23. Javier
    Javier avatar
    3 posts
    Member since:
    Mar 2011

    Posted 09 Mar 2011 Link to this post

    I don't know if this will be of any use to you anymore, but I found an easy way to customize the confirm text per row.

    The records I pull can either be active or inactive.  The "delete" button will just reverse the state.
    I wanted a relevant popup to alert the user of which state he's about to convert to.

    On the DataBound event of the grid itself I call a function called setDeactiveText().  


    Private Sub setDeactivateText()
       For i As Integer = 1 To rgdReportTemplates.Items.Count - 1
           If rgdReportTemplates.Items(i).GetDataKeyValue("Active") Then
               DirectCast(rgdReportTemplates.Items(i).Item("DeleteColumn").Controls(0), ImageButton).Attributes("onclick") = "if(!$find('rgdReportTemplates').confirm('Are you sure you want to set the record to INACTIVE?', event, 'Delete'))return false;"
           Else
               DirectCast(rgdReportTemplates.Items(i).Item("DeleteColumn").Controls(0), ImageButton).Attributes("onclick") = "if(!$find('rgdReportTemplates').confirm('Are you sure you want to set the record to ACTIVE?', event, 'Delete'))return false;"
           End If
       Next
    End Sub


     Basically I just update the onclick event of the imagebutton.  I pulled the javascript from a rendered page with a different message.

    rgdReportTemplates is the radgrid name
    DeleteColumn is the UniqueName for the GridButtonColumn

    Javier
  24. Robin
    Robin avatar
    5 posts
    Member since:
    Apr 2009

    Posted 15 Aug 2011 Link to this post

    Yes, I have to agree. This worked for me too:

    protected void AlternateEmailsRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        //Get the row from the grid.
        GridDataItem dataItem = e.Item as GridDataItem;
        if (dataItem != null)
        {
            // Delete //
            ImageButton button = dataItem["DeleteColumn"].Controls[0] as ImageButton;
            button.Attributes["onclick"] = string.Format("return confirm(\"{0}\");", string.Format(Resources.Messages.MESSAGE_DELETE_EMAIL_ADDRESS_CONFIRMATION, dataItem["Email"].Text));
        }
    }

    Good luck!
  25. Jean-Francois
    Jean-Francois avatar
    2 posts
    Member since:
    May 2013

    Posted 22 Aug 2013 Link to this post

    Just remove the "If TypeOf e.Item Is GridDataItem Then" check.  All your lines will be set correctly.

    With the "Trycast" method, it will take care of itself, you don't need to check if it's a GridDataItem.

    This is what I did and it worked great for all lines (I had the same problem by the way):

    Private Sub trgWEB_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles trgWEB.ItemDataBound
                TryCast(trgWEB.MasterTableView.GetColumn("trgWEB_Delete"), GridButtonColumn).ConfirmText = "Delete?"
                'If TypeOf e.Item Is GridDataItem Then
                'End If
    End Sub

  26. Terrah Mthombeni
    Terrah Mthombeni avatar
    1 posts
    Member since:
    Feb 2014

    Posted 12 Feb 2014 in reply to Jonx Link to this post

    Thanks for leading me to the solution.
  27. Waqas Aslam
    Waqas Aslam avatar
    8 posts
    Member since:
    Oct 2009

    Posted 25 Sep 2014 Link to this post

    Now you may add dynamic dialog message using the following:

    <telerik:GridButtonColumn CommandName="Delete" UniqueName="Delete" ButtonType="ImageButton"
         ImageUrl="~/Images/NavIcons/cross.png" ConfirmDialogType="RadWindow"
         ConfirmTextFields="OrderId" ConfirmTextFormatString="Are you sure you want to delete order# {0}?"
         ConfirmTitle="Delete Order!"></telerik:GridButtonColumn>


    *OrderId is a DataField which will insert its value at TextFormat {0}
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017