0

We have a simple asp.net grid view that shows some data and an ImageButton to edit the data.

Upon clicking the ImageButton we call the RowCommand event (server side event) to allow for edit of the data. The edit of the data comes unfortunately in the form of assigning the values to textbox controls that are inside a jquery dialog.

Now for some code to help you understand it:

In the grid view a rowcommand event:

 protected void gvActions_RowCommand(object sender, GridViewCommandEventArgs e)
        {
          var db = new DataClasses1DataContext();
          GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
          switch (e.CommandName)
            {
              case "Edit":
                    //wants to edit an action item
                    hdnOpenDialogActions.Value = "1";

                    ////set the fields to what is inside the grid
                    Label id = (Label)row.FindControl("lblIssueActionID");
                    var rec = db.IssueActions.Single(x => x.IssueActionID == Convert.ToInt32(id.Text));

                    if (rec == null)
                        return;

                    //assign textboxes that are located inside of a jquery grid.
                    lblIssueActionID.Text = id.Text;                                    //assign ID of action item
                    lblDialogOpenDateValue.Text = rec.OpenDate.ToShortDateString();
                    txtDialogTargetDateValue.Text = rec.TargetDate.ToShortDateString();
                    txtDialogClosedDateValue.Text = rec.ClosedDate.ToString();

                    hdnActionText.Value = rec.IssueAction1;
                    txtActionHTML.Value = rec.IssueActionHTML;
                    hdnActionResolutionText.Value = rec.IssueActionResolution;
                    txtActionResolutionHTML.Value = rec.IssueActionResolutionHTML;

                    hdnResponsibleValue.Value = rec.ResponsibleID.ToString();
                    lblResponsibleValue.Text = rec.ResponsibleContact.FullName;        
                    break;
            }
        }

The hdnOpenDialogActions is used to ensure the dialog is open. Here is some of the jquery, as you see initially I hide it:

$("#dialogActions").hide();
            $("#dialogActions").dialog({
                autoOpen: false,
                appendTo: "form:first",
                width: 'auto',
                height: 'auto',
                modal: true,
                open: function (event, ui) {
                    $('#dialogActions').css('overflow', 'hidden'); //this line does the actual hiding
                },
                close: function (event, ui) {
                    //if someone x's out (Closes the dialog) we better make sure we
                    //set the hidden field to 0 so that the dialog doesn't open up again on post back
                    $("#MainContent_hdnOpenDialogActions").val("0");
                }
            });

Here's the function that keeps it open (when I set the hidden field to 1 it means open the dialog):

 if ($("#MainContent_hdnOpenDialogActions").val() === "1") {
                $("#dialogActions").dialog("open");
                $("#MainContent_txtActionHTML").focus();
            } else {
                $("#dialogActions").hide();
            }

Here is the actual jquery grid (sorry for Table use :)):

            <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Always" ChildrenAsTriggers="True">
            <ContentTemplate>       
        <div id="dialogActions" title="Issue Owner">
                <table>
                    <tr>
                        <td class="labelField"><asp:Label ID="lblDBA" runat="server" Text="Open"></asp:Label></td>
                        <td class="valueField">
                            <asp:Label ID="lblDialogOpenDateValue" runat="server"></asp:Label>
                            <asp:Label ID="lblIssueActionID" runat="server" Visible="False"></asp:Label>
                            <asp:HiddenField ID="HiddenField1" runat="server" />
                        </td>
                        <td class="labelField">
                            <asp:Label ID="lblDRegion0" runat="server" Text="Responsible:"></asp:Label>
                        </td>
                        <td class="valueField">
                            <asp:Label ID="lblResponsibleValue" runat="server" ToolTip="Responsible"></asp:Label>
&nbsp;<asp:HyperLink ID="hlOpenResponsible" runat="server" NavigateUrl="#" Text="&lt;img src=&quot;../../Images/edit.png&quot; alt=&quot;Click to edit.&quot;/&gt;" ToolTip="Click to change user reports to..."></asp:HyperLink>&nbsp;|&nbsp;<asp:HyperLink ID="hlClearResponsible" runat="server" NavigateUrl="#" Text="&lt;img src=&quot;../../Images/delete.png&quot; alt=&quot;Click to clear selection.&quot;/&gt;" ToolTip="Click to clear selection."></asp:HyperLink>
                            <asp:HiddenField ID="hdnResponsibleValue" runat="server" />
                            <asp:HiddenField ID="hdnOpenResponsible" runat="server" Value="0" />
                        </td>
                    </tr>
                    <tr>
                        <td class="labelField">
                            <asp:Label ID="lblDRegion" runat="server" Text="Target:"></asp:Label>
                        </td>
                        <td class="valueField">
                            <asp:TextBox ID="txtDialogTargetDateValue" runat="server" CssClass="datePicker"></asp:TextBox>
                        </td>
                        <td class="labelField"><asp:Label ID="lblDPMIssue" runat="server" Text="Closed:"></asp:Label></td>
                        <td class="valueField">
                            <asp:TextBox ID="txtDialogClosedDateValue" runat="server" CssClass="datePicker"></asp:TextBox>
                        </td>
                    </tr>
                   <tr>
                        <td class="labelField">
                            <asp:Label ID="lblDPMIssue0" runat="server" Text="Action:"></asp:Label>
                        </td>
                        <td class="valueField" colspan="3">
                            <textarea id="txtActionHTML" runat="server" class="tinyeditor" cols="5" rows="5" title="Enter the action item."></textarea><asp:HiddenField ID="hdnActionText" runat="server" />
                            <asp:HiddenField ID="hdnActionHTML" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td class="labelField">
                            <asp:Label ID="lblDPMIssue1" runat="server" Text="Resolution:"></asp:Label>
                        </td>
                        <td class="valueField" colspan="3">
                            <textarea id="txtActionResolutionHTML" runat="server" class="tinyeditor" cols="5" rows="5" title="Enter the action item resolution."></textarea><asp:HiddenField ID="hdnActionResolutionText" runat="server" />
                            <asp:HiddenField ID="hdnActionResolutionHTML" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td class="labelField" colspan="4">
                            <asp:Button ID="btnSaveAction" runat="server"  Text="Submit" OnClientClick="SubmitContent();" ToolTip="Submit / Save changes?" OnClick="btnSaveAction_Click" />
                        </td>
                    </tr>
                </table>
         </div>
                </ContentTemplate>
            </asp:UpdatePanel>

I set a breakpoint and I can see the code setting the textboxes but as soon as the dialog opens up everything is not really updated. The textboxes are empty etc...even though the code behind is showing that they are getting values.

My front end skills are pretty bad, so if someone can let me know why this is happening (could this be due to it being a server side control and it causing a post back after the row command event)?

8
  • Do you have this wrapped in an UpdatePanel by chance? Commented Jan 31, 2014 at 22:07
  • Well I guess the question is should I wrap it in an update panel or keep it out of an updatepanel. I think I tried wrapping it in an update panel but maybe I did that part wrong. Commented Jan 31, 2014 at 22:10
  • The reason I asked is that it sounds like maybe an update panel (if you're using one) is not getting updated when the server sends the data to the client. If you can debug the code behind and see that the values are getting set, but the webpage is not displaying them, I think you must be doing something asynchronously... Is there currently an update panel wrapped around this html? Commented Jan 31, 2014 at 22:13
  • I put it in an update panel. In the code behind I can see the values getting set correctly...But as soon as the dialog comes up and opens, everything is cleared as if it was never sent. It leads me to believe it is some updatepanel issue but not sure what to do? Commented Jan 31, 2014 at 22:18
  • Can you post the update panel control? I'm wondering what the UpdateMode is set to - either Conditional or Always? If conditional - you have to set the trigger to the button click. If always - you should be good to go... Commented Jan 31, 2014 at 22:20

3 Answers 3

1

The answer is a combination of the two other answers and some client-side help. As macoms code shows the key element to change on your aspx page, updatemode=conditional

<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">

And, you might need to add an asynchronous trigger to each and every edit button

ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(edit_control);

And that will need to be bound in the OnItemDataBound event which you can find more information on here if you need it.

Lastly, you will need to refresh your update panel once finished in your edit command as gbs points out by using the update() command

    lblResponsibleValue.Text = rec.ResponsibleContact.FullName;
    UpdatePanel1.Update();
    break;
}

As a webforms client-side guy put your update panels inside your jQuery object rather than the other way around. You'll encounter less grief. This looks like that might be the issue too. The updatepanel is staying put, but your jQuery append is moving the dialog and NOT the update panel. Move your updatepanel inside the div.

<div id="dialogActions" title="Issue Owner">
    <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
        <ContentTemplate>       
            <table>

That should fix you up.

Sign up to request clarification or add additional context in comments.

Comments

0

Okay I think I see the issue. You need to use the triggers section to tell this update panel what button's click causes it to update.

Something like:

<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional" ChildrenAsTriggers="True">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="gvActions" />
    </Triggers>
    <ContentTemplate>
        <div id="dialogActions" title="Issue Owner">
            <table>
                <!-- text boxes you want to be updated -->
            </table>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:GridView runat="server" ID="gvActions"></asp:GridView>

I'm not positive that the trigger will be gvActions so you may have to play around with it. Let me know if this helps or if you are still having trouble. I will be away from my pc until later tonight/tomorrow fyi.

4 Comments

This wont work as the pencil (edit icon) is an imagebutton inside of a gridview (it can appear based on the number of rows).
I see what you mean, but I'd give it a try since it will call the gridview's rowCommand event regardless. I will take another look when I get a chance this weekend.
This doesnt make sense as gvActions is a gridview.
Jon you can add gridviews to update panel triggers, they take an event in the trigger syntax and you can bind the trigger to events like ItemCommand or EditCommand, etc.
0

If your GV is outside the UpdatePanel, you will have to manually refresh the updatepanel on postback.

So right inside your Edit switch case, before the break add this line:

....
UpdatePanel1.Update();
break;
....

What it is doing is programmatically updating the updatepanel.

1 Comment

This may be correct, the update panel is set to always and it might need to be set to conditional, then it can be updated as such. This is the only way I've been able to get this done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.