views:

37

answers:

2

On details view, I would like to hide the new button.

On page load I have successfully done so by the following code:

dtvwMyProfile.Rows[5].Cells[0].Controls[2].Visible = false;

But how do I hide the New button when I hit cancel or update button after I am done editing.

The New button keeps showing up. How do I hide it completely from the screen.

In some event, the visible property keeps changing to true and how do i find out that event?

I want to be able to do it at run time instead of design time.

A: 

Hey,

Maybe try to do that in the ModeChanged event handler, which fires after the mode changes... But can you ensure new is always at position 2? You may want to verify the button by its text or command name.

Brian
ModeChanged did not work. It does how ever work for PageLoad event. Some thing is changing that button's visible property back to True and I dont know what is it. This is just a test/learning code that is why for now I am choosing position 2. Please help me!!
dotnet-practitioner
If page load event works for you, but it gets changed back, try to move it back to a later event, like page prerender. This may occur after the code that shows the button again.
Brian
+1  A: 

Dynamically changing the properties of child controls created by the DetailsView is not recommended.

If the button is being created by the DetailsView itself then all you need to do is set AutoGenerateInsertButton to false and you can do that in Page_Load.

I do not recommend randomly selecting a page event and handling it. If you do that then chances are it will just break again when you change something else.

Eilon