Ticket Q537685
Visible to All Users

ASPxButtonEdit - How to change button image on client side

created 11 years ago

Hello, how can I change ASPxButtonEdit button image on client side.

ASPX code snippet - column definition on ASPxGridView:

ASPx
<dx:GridViewDataButtonEditColumn FieldName="ShopID" Caption="Shop ID" VisibleIndex="3"> <PropertiesButtonEdit MaxLength="10"> <Buttons> <dx:EditButton Position="Right" ToolTip="Generate next ID in sequence."> <Image Url="/_layouts/OffersTool/img/star.png" /> </dx:EditButton> </Buttons> <ClientSideEvents ButtonClick="function (s, e) { onshopidbuttonClick(s, e); }" Init="function (s, e) { onshopidbuttoninit(s, e); }" /> <ValidationSettings SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip" Display="Dynamic"> <RequiredField IsRequired="true" ErrorText="Value must be filled." /> </ValidationSettings> </PropertiesButtonEdit> </dx:GridViewDataButtonEditColumn>

JavaScript code snipped - there I need to change button image:

JavaScript
function onshopidbuttonClick(s, e) { var button = s.GetButton(0); button.ImageUrl = "/path/img.gif"; ??? }

Thank you for any suggestion.

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hi,
We have already answered this question in the context of the ASPxButtonEdit - Changing the button's image in code ticket. For this reason, I believe that it makes sense to close this ticket as its duplicate. Attached is a small code example that illustrates how to apply the solution in case of ASPxGridView. Should you need any further clarification, feel free to ask. I will be glad to help you.
Thanks,
Alessandro.
Updated by Larry (DevExpress Support):
Use the following code to implement the required task:

function onshopidbuttonClick(s, e) {
            var button = s.GetButton(0);
            var image = button.getElementsByTagName("img")[0];
            image.src = "path/img.png";
        }
Please note that the GetButton method is undocumented. Generally, we do not recommend using such methods since they can operate unexpectedly. Moreover, an undocumented method can be changed without notifications with a next release. In your scenario, however, this seems to be the only possible way to proceed.

    Show previous comments (1)
    DevExpress Support Team 11 years ago

      Hello,
      Use the following code to implement the required task:

      C#
      function onshopidbuttonClick(s, e) { var button = s.GetButton(0); var image = button.getElementsByTagName("img")[0]; image.src = "path/img.png"; }

      Please note that the GetButton method is undocumented. Generally, we do not recommend using such methods since they can operate unexpectedly. Moreover, an undocumented method can be changed without notifications with a next release. In your scenario, however, this seems to be the only possible way to proceed.
      Please let me know if you need further assistance.

        Thank you, works perfect.

        DevExpress Support Team 11 years ago

          You are always welcome! I have updated our answer.
          Once your question has been resolved to your satisfaction, you can mark it as a Solution. Your question status will immediately become Closed.
          SC2 FAQ

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.