Поделиться через


How to hide the Cancel button in a custom SharePoint application page

When you’re writing custom SharePoint Application Pages, you may want to design the pages with the look and feel of SharePoint. This can be achieved by using the CSS stylesheets provided by MOSS, but also by using the ASP.NET controls that are delivered together with MOSS.

In one of my projects, I used the InputFormSection control, together with ButtonSection control to put an OK and Cancel button at the bottom right side of the page. This was (part of) the code I wrote:

<wssuc:ButtonSection runat="server">
<Template_Buttons>
<asp:Button runat="server" class="ms-ButtonHeightWidth" Text="Update" ID="UpdateButton"
CausesValidation="True" CommandName="Update" OnClick="UpdateButton_click" />
&nbsp;
<asp:Button runat="server" class="ms-ButtonHeightWidth" Text="Cancel" ID="CancelButton"
CausesValidation="False" CommandName="Cancel" OnClick="CancelButton_click" />
</Template_Buttons>
</wssuc:ButtonSection>

 

Now, what happens if you run this, is that you end up with 2 cancel buttons instead of 1. The first one will trigger your event handler, the other one doesn’t do anything…

image

You can solve this by setting the ShowStandardCancelButton proprty on the ButtonSection control to “False”:

<wssuc:ButtonSection runat="server" ShowStandardCancelButton="false">
<Template_Buttons>
<asp:Button runat="server" class="ms-ButtonHeightWidth" Text="Update" ID="UpdateButton"
CausesValidation="True" CommandName="Update" OnClick="UpdateButton_click" />
&nbsp;
<asp:Button runat="server" class="ms-ButtonHeightWidth" Text="Cancel" ID="CancelButton"
CausesValidation="False" CommandName="Cancel" OnClick="CancelButton_click" />
</Template_Buttons>
</wssuc:ButtonSection>

Now, you get the desired result:

image

Comments