1

I have a master page that has an update panel on it. One of the pages for the application I'm working on has a custom control with some asp:textboxes on it. That control also has a gridview.

When an asp:linkbutton for a row is clicked the OnRowCommand event fires and does its magic correctly, one part of which is setting the asp:textbox's "Text" property. This works.

My problem is that the update isn't being reflected in the UI.

The UpdatePanel:

<asp:ScriptManager ID="scriptManager" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="updPanel" runat="server">
        <ContentTemplate>
              [...more code...]

The LinkButton:

 <ItemTemplate>
         <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("ID")%>' CommandName="EDIT" runat="server">Edit</asp:LinkButton>     
</ItemTemplate>

The Event Handler:

protected void RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "EDIT":
                    //stuff happens here
                    [ASP:Textbox].Text = [Result of stuff that happened];
                     ^this is what isn't reflected on the page
                    break;

I know I'm missing something with the page life cycle but I'm drawing a blank.

2 Answers2

2

Just spent few hours on this.

As it seems, changes are reflected only if CommandName property is set on something other then "Edit" (and any other standard commands). Try to set it to "EditThis", it works for me.

Miroslav Zadravec
  • 3,510
  • 5
  • 24
  • 35
  • 1
    Oh god. I went through this myself a couple months ago. In a `ListView` there are reserved `CommandName`s that implement built in functionality. Unfortunately, the MS design team didn't see fit to throw any kind of exception if you set a command name equal to one of them even if it would cause no action in your particular design. It was quite a forehead slapper which I did not figure out until I actually stepped through MS' source code to see why no event was being raised. Honestly I'm not sure why they would block the event even if it does something internally. Very confusing. – Jamie Treworgy Apr 03 '11 at 17:25
  • Holy crap! I won't be able to change this until tomorrow but thank you for posting! If it works, I'll come back and "accept" the answer. Thanks again! –  Apr 04 '11 at 12:24
0
protected void RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "EDIT":
                    //stuff happens here
                    [ASP:Textbox].Text = [Result of stuff that happened];
                     ^this is what isn't reflected on the page
                    // ADD THIS
                    updPanel.Update();
                    break;
TheGeekYouNeed
  • 7,509
  • 2
  • 26
  • 43
  • Tried that, no dice. In the debugger I can see the textbox getting set to the correct value but the UI never updates. –  Feb 03 '11 at 13:30