2012-04-25 94 views
0

我有一個UpdatePanel,其中一個GridView,並在其中一個Repeater。有一個按鈕可以添加評論。此按鈕發回,但id不運行後面的功能代碼。這裏是我的代碼ASP.NET按鈕不運行相關功能

<updatepanel> 
    <gridview> 
     <repeater> 
      <asp:Button ID="kitapVarYorumEkle" runat="server" 
       CommandArgument='<%#Eval("id") %>' 
       CommandName='<%# GridView1.Rows.Count.ToString() %>' 
       Text="Yorum ekle" class="blueButton" 
       OnClick="kitapVarYorumEkle_Click" /> 
     </repeater> 
    </gridview> 
</updatepanel> 

代碼的JS內部:

protected void kitapVarYorumEkle_Click(object sender, EventArgs e) 
{ 
     kitapVarYorum temp = new kitapVarYorum(); 

     if (Session["id"] != null) 
     { 
      temp.uyeId = Convert.ToInt32(Session["id"]); 
     } 

     Button btn = (Button)sender; 
     temp.kitapVarId = Convert.ToInt32(btn.CommandArgument); 

     string text = ""; 

     GridViewRow row = GridView1.Rows[Convert.ToInt32(btn.CommandName)]; 

     if (row != null) 
     { 
      TextBox txt = row.FindControl("txtYorum") as TextBox; 

      if (txt != null) 
      { 
       text = txt.Text; 
      } 
     } 

     temp.icerik = text; 
     var db = Tools.DBBaglanti(); 
     db.kitapVarYorums.InsertOnSubmit(temp); 
     db.SubmitChanges(); 

     // Page.Response.Redirect(Page.Request.Url.ToString(), true); 
    } 
} 

我已經嘗試過了的控制之外,它的工作原理

回答

0

您是否嘗試過的ItemCommand的方法呢?

<asp:Button 
    CommandArgument='<%#Eval("id") %>' 
    CommandName="yourCommandNameOfChoice" 
    Text="Yorum ekle" 
    ID="kitapVarYorumEkle" 
    class="blueButton" runat="server" 
    OnClick="kitapVarYorumEkle_Click" /> 

現在添加ItemCommand事件的轉發:

protected void yourRepeater_ItemCommand(object source , RepeaterCommandEventArgs e) 
{ 
    switch(e.CommandName) 
    { 
      case "yourCommandNameOfChoice": 
       // Your Code Here 
       break; 
    } 
} 
+0

是它的工作表示感謝。 – osmanraifgunes 2012-05-16 10:05:17