0

I have an asp page with a gridview on. I have also added a clientscript to each bound row to highlight/un-higlight on mouse over/out. I have added an asp:button as a templatefield and bound a value to the CommandArgument. In IE and FIrefox I get the expected behaviour where the CommandName is passed to the _RowCommand event. However, when in Safari I only ever see the CommanName of "Select" passed to RowCommand.

The expected behaviour is that when a bound row is clicked the "Select" paramater is passed to the RowCommand event. When the Button in the row is clicked the argument "Remove" is passed.

protected void gvContacts_RowDataBound(object sender, GridViewRowEventArgs e)
{

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onMouseOver", "Highlight(this)");
        e.Row.Attributes.Add("onMouseOut", "UnHighlight(this)");

        e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gvContacts, "Select$" + e.Row.RowIndex);

        e.Row.Attributes["style"] = "cursor:pointer";
    }
}


protected void gvContacts_RowCommand(object sender, GridViewCommandEventArgs e)
{                

    switch (e.CommandName)  //Always "Select" when browser is Safari.  
    {
        case "Select":
            Session["clientID"] = gvContacts.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text;
            Response.Redirect("../Contacts/ContactEdit.aspx?readin=1");
            break;
        case "Remove":
            //Remove the client from the list
            Company company = new Company();
            company.Get(Int32.Parse(Session["CompanyID"].ToString()), ((Model)Session["model"]).ConnectionString);
            company.RemoveUser(Int32.Parse(e.CommandArgument.ToString()));
            BindGrid(company.ID);
            break;
    }                
}

HTML for itemtemplate

<asp:TemplateField>
    <ItemTemplate>
        <asp:Button ID="btnRemove" runat="server" Text="Remove" CommandName="Remove" OnClientClick="return confirmRemove();"
                                    CommandArgument='<%# Eval("ID") %>' />
   </ItemTemplate>

Any thoughts would be appreciated. Thanks

user3006802
  • 53
  • 1
  • 3
  • you gave command name "REMOVE" so how can row command event understand that button was clicked from safari and if it then you didn't mention the code for it... – Dhaval Jan 23 '15 at 03:50

1 Answers1

0

I think You should First Check that Button was clicked From which browser and if it was from safari than Change Command Name ..

  protected void gvContacts_RowCommand(object sender, GridViewCommandEventArgs e)
    {                
    System.Web.HttpBrowserCapabilities browser = Request.Browser;
      if(browser.Browser=="Safari") //Check The Browser 
       {
          e.CommandName="Select";
       }
        switch (e.CommandName)  //Always "Select" when browser is Safari.  
        {
            case "Select":
                Session["clientID"] = gvContacts.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text;
                Response.Redirect("../Contacts/ContactEdit.aspx?readin=1");
                break;
            case "Remove":
                //Remove the client from the list
                Company company = new Company();
                company.Get(Int32.Parse(Session["CompanyID"].ToString()), ((Model)Session["model"]).ConnectionString);
                company.RemoveUser(Int32.Parse(e.CommandArgument.ToString()));
                BindGrid(company.ID);
                break;
        }                
    }
Dhaval
  • 2,341
  • 1
  • 13
  • 16