1

我试图在gridview 中执行linkbutton 的click evnet,而这个网格视图在UpdatePanel 控件中。我想在同一页面上单击框架中的链接按钮时显示信息/数据。但框架显示另一个 .aspx 页面。

protected void gvEditInvoice_RowCommand(object sender, GridViewCommandEventArgs e)
{  

    try
     {
          if (e.CommandName.ToUpper().Contains("LINKCLICK"))
          {                    

               GridViewRow gvr = ((Control)e.CommandSource).Parent.Parent as GridViewRow;
               int rowIndex = Convert.ToInt32(gvr.RowIndex);

               LinkButton lbtn = (LinkButton)gvEditInvoice.Rows[rowIndex].FindControl("lnbtnBillingEntityName");//.PostBackUrl = "~/somewhere/" + Session["path"].ToString();                    
               ScriptManager1.RegisterPostBackControl(lbtn);
           //RegisterPostBackControl() methods is used to postback full page after linkbutton clicked

               string urlPath = e.CommandArgument.ToString(); //.aspx Page URL is getting from field
           mainFrame.Attributes["src"] = @"/eis/IMS/WebUI/Prototype/" + urlPath;
           //mainFrame is my frame and showing another .aspx in this area of same .aspx page
           }
      }
      catch (Exception ex)
      {
      }
}

一切都很好,但问题是我必须点击链接按钮两次,然后我才能得到结果。你能帮我解决这个问题吗?

提前致谢

4

1 回答 1

2

如下添加行数据绑定事件并RegisterPostBackControl从行命令事件中删除

protected void gvEditInvoice_RowDataBound(object sender, GridViewRowEventArgs e)  
{  
   LinkButton lb = e.Row.FindControl("lnbtnBillingEntityName") as LinkButton;  
   AjaxControlToolkit.ToolkitScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);
}  
于 2013-04-15T13:07:47.730 回答