Seehyung Lee
Seehyung Lee

Reputation: 610

jQuery Dialog How to pass 'True' when button is clicked

My code below is working fine except when a button "Continue" is clicked it doesn't send a value of true.

<script type="text/javascript">
    function EmpDelete(f_name) {
        $("#fName").text(f_name);
        $('#dialog').dialog({            
            title: "Delete Employee?",            
            modal: true,
            width: 500,
            height: 250,            
            buttons: {
                "Cancel": function () {
                    $(this).dialog("close");
                },
                "Continue": function () {                    
                    $(this).dialog("close");
                    // return true;
                }                
            }            
        });                        
        return false;
    };    
</script>

when imgDelete ImageButton is clicked the above jQuery event is called.

e.Row.Cells[iDelete].Controls.Add
    (new ImageButton
    {
        ImageUrl = "Images/database_delete.png",
        CommandArgument = e.Row.RowIndex.ToString(),
        CommandName = "Delete",
        ID = "imgDelete",
        CssClass = "imgDelete",                 
        OnClientClick = "return EmpDelete('" + e.Row.Cells[iFNmae].Text + "');",    
        ClientIDMode = System.Web.UI.ClientIDMode.Static
    });

How can I make the "Continue" button on jQuery returns a value of true so my "RowCommend" event can do the further process?

protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Delete")
    {

    } 
}

Upvotes: 1

Views: 643

Answers (3)

Seehyung Lee
Seehyung Lee

Reputation: 610

I solved it by using __doPostBack(uniqueID, ''); on the jQuery "Continue" button and

On the Page_Load() Event I added

 if (!Page.IsPostBack)
    {
        ClientScript.GetPostBackEventReference(gvEmployee, string.Empty);
    }

And I called the jQuery Dialog on Gridview_RowDataBound event

e.Row.Cells[iDelete].Controls.Add
            (new ImageButton
            {
                ImageUrl = "Images/database_delete.png",
                CommandArgument = e.Row.RowIndex.ToString(),
                CommandName = "Delete",
                ID = "imgEmpDelete" + e.Row.Cells[iID].Text,
                **OnClientClick = "javascript:return rowAction(this.name)",**
                ClientIDMode = System.Web.UI.ClientIDMode.Static
            });

Hope it helps anyone.

Upvotes: 0

Rick
Rick

Reputation: 142

I realized I had done something similar to this and looked back at my code to see why I hadn't used the second 'argument' parameter I mentioned in my other answer.

In my case, instead of a GridView, I had a Repeater. A button in each row triggered the jQuery UI dialog pop-up. However, even though I had multiple rows, I had a single jQuery UI dialog; its contents changed based on which row's button had been pressed. My dialog box had forms field, so when the dialog button was pressed, I would make a call to the javascript function generated by the GetPostBackEventReference() method. Since the fields in the dialog box's form were being submitted, I didn't need to specify any argument.

My point is that in your case, instead of using the second 'argument' parameter I mentioned in my other answer, you could probably just create a HiddenField in your dialog box. If you're submitting form fields in your dialog box, then you'll be able to capture that HiddenField in your RowCommand event handler. Just set its value to True before initiaing the PostBack. In your case, I'm assuming you'd also need a hidden field to identify which employee should be deleted (some type of EmployeeID value).

Upvotes: 1

Rick
Rick

Reputation: 142

Try looking into the ClientScriptManager.GetPostBackEventReference method http://msdn.microsoft.com/en-us/library/ms153112.aspx

See the following post for a description of how to use it... asp:Button in jQuery dialog box not firing OnClick event

I haven't used it to pass along a CommandArgument, but there is a second parameter for the method which states that it's for an 'argument'. You can try passing your value of True in that argument parameter and see if you can capture it in your RowCommand event handler.

Upvotes: 1

Related Questions