c#
  • asp.net
  • 2015-01-21 8 views 0 likes 
    0

    이 템플릿 필드가 내 gridview에 있습니다.GridView LinkButton에서 "onclick"이벤트 사용 안 함

    <asp:TemplateField HeaderText="PersonID"> 
        <ItemTemplate> 
          <asp:LinkButton runat="server" ID="BtnPersonDashboard" Text='<%# Bind("PersonId") %>' OnClientClick='<%# "PopupPersonRecord("+ Eval("RefId") +","+Eval("MemberId")+");" %>' /> 
        </ItemTemplate> 
    </asp:TemplateField> 
    

    이 버튼은 정상적으로 작동하며 버튼의 다시 게시를 비활성화하면됩니다. 다음과 같이 나는 Gridview의 "RowDatabound"이벤트에 그렇게 시도했다 :

    protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs e) 
         { 
          if (e.Row.RowType == DataControlRowType.DataRow) 
          { 
           // disable the Person id link button post back 
           ((LinkButton)e.Row.Cells[1].Controls[0]).Attributes.Add("onclick", "return false;"); 
    
          } 
         } 
    

    그러나, 나는 전혀하는 LinkButton에 대한 참조를 얻을 수없는 것. Debug에서 e.Row.Cells[1].Controls[0]을 "보려고"했는데 그 값은 "Text = {1235}"< - 내 Person ID로 표시됩니다.

    왜 그 컨트롤에 대해 "Linkbutton"대신 "Text"값이 표시되는지 잘 모르겠습니다. 어떤 아이디어가 문제 일 수 있습니까? onclick 이벤트를 비활성화 할 수있는 다른 제안 사항이 있습니까?

    답변

    2

    , 당신은 단지 거짓 수익을 추가해야합니다;

    <asp:LinkButton 
        ... 
        OnClientClick='<%# "PopupPersonRecord("+ Eval("RefId") +","+Eval("MemberId")+"); return false;" %>' /> 
    
    OnClientClick

    참고 : 위의 방법을 할 경우, RowDataBound 이벤트 내부 "onclick"을 추가하지 마십시오.

    0

    단지 코드 숨김으로 사용 중지하십시오. 이 같은

    BtnPersonDashboard.Enabled = false; 
    
    2

    시도 뭔가 : 당신이하는 LinkButton에 대한 포스트 백을 사용하지 않으려면

    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
        // find the control on the row on gridView 
        var btnPersonDashboard = e.Row.FindControl("BtnPersonDashboard") as LinkButton; 
    
        // check if the control was found and disable it 
        if (btnPersonDashboard != null) 
         btnPersonDashboard.OnClientClick = "return false"; 
    } 
    
    +1

    'OnClientClick' 속성 만 변경하십시오. 내 게시물을 편집했습니다. 너를 도와 줘서 다행이야! –

    관련 문제