Have Button re-appear immediately after clicking button in ListView row

Posted by Soeren on Stack Overflow See other posts from Stack Overflow or by Soeren
Published on 2010-03-12T10:21:41Z Indexed on 2010/03/12 10:27 UTC
Read the original article Hit count: 576

Filed under:
|
|
|

I have 4 buttons on a page. Each button opens a modal window and let’s the user input data in a form. When the user hits the save button in the modal, a ListView appears on the page with the submitted data.

The button the user clicked to open the modal window is set to visible=false, so it’s gone when the row is added to the ListView. Now there are 3 buttons and the same goes for those; when the user hits a button, a modal appears, and when the modal form is submitted, the button disappears and a row is added to the ListView.

In the ListView row, there is a delete button. When this button is clicked, the row is deleted and the button that was initially clicked to add this row (and open the modal), SHOULD reappear, but it doesn’t. The row disappears, but I have to refresh the page before the button comes back. There is a ScriptManager on the masterpage, so I guess this is an AJAX partial refresh issue. I tried adding different events, but I can’t find the one that fires at the right time.

I use an ObjectDataSource to fill the ListView, and the data comes from a database, wrapped in a business object.

This code loads a business object in a List<> and checks if the user inserted an item of a specific type. If he did, the button he used to open the modal is hidden. This works fine (maybe not the most elegant)

_goals = GoalManager.GetGoalsByUser(UserID);

            if (_goals != null)
            {
                foreach (Goal _goalinlist in _goals)
                {
                    if (_goalinlist.GoalType == 1)
                    {
                        Button1.Visible = false;
                        goalid1 = true;
                    }
                    if (_goalinlist.GoalType == 2)
                    {
                        Button2.Visible = false;
                        goalid2 = true;
                    }
                    if (_goalinlist.GoalType == 3)
                    {
                        Button3.Visible = false;
                        goalid3 = true;
                    }
                    if (_goalinlist.GoalType == 4)
                    {
                        Button4.Visible = false;
                        goalid4 = true;
                    }
                }

            }

As you can see, I tried setting a boolean, and then check it when the page is re-loaded. But the problem (I guess) is that the whole page isn't refreshed when the delete button is clicked in the ListView.

This is the delete button in the ListView:

<asp:ImageButton ID="ImageButton2" runat="server" CommandName="Delete" CausesValidation="false"
                    ToolTip="Delete" CommandArgument='<%#Eval("GoalID")%>' ImageUrl="delete.gif"
                    OnClientClick="return confirm('Delete this post?');" CssClass="button"/>

I guess the question is, how do I make the button re-appear right after the ListView button is clicked?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about listview