Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7967987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:00:24+00:00 2026-06-04T07:00:24+00:00

I have this markup: <asp:DetailsView ID=dvDatabase OnModeChanging=dvDatabase_ModeChanging> <HeaderTemplate> <asp:Button ID=btnView runat=server CausesValidation=False CommandName=Cancel Text=View

  • 0

I have this markup:

<asp:DetailsView ID="dvDatabase" OnModeChanging="dvDatabase_ModeChanging">
    <HeaderTemplate>
        <asp:Button ID="btnView" runat="server" CausesValidation="False" CommandName="Cancel"
            Text="View" CssClass="btn btn-primary" Visible="false" />
        <asp:Button runat="server" CausesValidation="False" CommandName="Edit"
            Text="Edit" CssClass="btn btn-success" ID="btnEdit" />
        <asp:Button runat="server" CausesValidation="False" CommandName="Delete"
            Text="Delete" CssClass="btn btn-danger" />
    </HeaderTemplate>
    ...

Then I have this C#:

protected void dvDatabase_ModeChanging(object sender, DetailsViewModeEventArgs e)
{
    bool isEdit = DetailsViewMode.Edit == e.NewMode;
    DetailsView view = (DetailsView)sender;
    Button viewButton = (Button)view.FindControl("btnView");
    Button editButton = (Button)view.FindControl("btnEdit");
    viewButton.Visible = isEdit;
    editButton.Visible = !isEdit;
}

I’ve done some debugging and the Visible property gets set correctly, but I never see the buttons change. I hit the Edit button and I’m in edit mode, but the Edit button is still displayed and the View button is still hidden. I’ve tried finding the buttons via dvDatabase.FindControl directly, rather than using the object sender variable, but that doesn’t work either. I tried to refer to the buttons with variables based on the ID attribute in the markup, but btnView and btnEdit variables/properties don’t exist. What’s going on?

Edit: I switched to OnModeChanged as per Tim’s suggestion, but the buttons still don’t change. Here’s my C# now:

protected void dvDatabase_ModeChanged(object sender, EventArgs e)
{
    DetailsView view = /*(DetailsView)sender*/dvDatabase;
    bool isEdit = DetailsViewMode.Edit == view.CurrentMode;
    LinkButton viewButton = (LinkButton)view.FindControl("btnView");
    LinkButton editButton = (LinkButton)view.FindControl("btnEdit");
    viewButton.Visible = isEdit;
    editButton.Visible = !isEdit;
}

I tried using the object sender as well as the dvDatabase class variable, but neither seemed to have an effect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:00:25+00:00Added an answer on June 4, 2026 at 7:00 am

    Use the DetailsView‘s DataBound event instead and only databind the DetailsView if(!Page.IsPostback). You also need to handle the ItemCommand event to call the appropriate ChangeMode method and databind the DetailsView.

    protected void dvDatabase_DataBound(Object sender, EventArgs e)
    { 
        var view = (DetailsView)sender;
        var btnView = (Button)view.FindControl("btnView");
        var btnEdit = (Button)view.FindControl("btnEdit");
        switch (view.CurrentMode)
        { 
            case DetailsViewMode.ReadOnly:
                btnView.Visible = false;
                btnEdit.Visible = true;
                break;
            case DetailsViewMode.Edit:
                btnView.Visible = true;
                btnEdit.Visible = false;
                break;
            case DetailsViewMode.Insert:
                btnView.Visible = false;
                btnEdit.Visible = false;
                break;
            default:
                break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following ASP-Markup: <asp:Button runat=server ID=btnSubmit meta:resourcekey=btnSubmit CssClass=submit OnClick=btnSubmit_Click /> And the
I have this markup: <asp:Repeater ID=appsRepeater runat=server> <ItemTemplate> <li> <div class=clearfix> <a href=---some code
I have some markup like this: <form id=ddlSelections runat=server> <asp:ScriptManager ID=ScriptManager1 runat=server EnablePartialRendering=true />
I have the following markup: <asp:DropDownList ID=dd1 AutoPostBack=true runat=server> <asp:ListItem Value=1>1</asp:ListItem> <asp:ListItem Value=2>2</asp:ListItem> </asp:DropDownList>
In my repeater I have the following markup: <asp:Repeater runat=server id=TeamsRepeater OnItemDataBound=TeamsRepeater_ItemDataBound ClientIDMode=Predictable> <ItemTemplate>
I have the following ASP.NET markup: <asp:regularexpressionvalidator id=RegularExpressionValidator7 runat=server ControlToValidate=Email1 ErrorMessage=Email not valid ValidationExpression=\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*>
I have got a BulletedList with DisplayMode=HyperLink . <asp:BulletedList runat=server DisplayMode=HyperLink ID=LevelsList></asp:BulletedList> I add
Let's say I have a rolegroup as follows: <asp:LoginView ID=lvDoSomeStuff runat=server> <RoleGroups> <asp:RoleGroup Roles=RoleOne,RoleTwo>
I have this markup in an MVC app. <div id=ingredientlistdiv> <% Recipe recipe =
Suppose I have this html markup: <div id=wrapper> <pre class=highlight> $(function(){ // hide all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.