2017-06-30 134 views
0

內轉發我有更新面板內轉發如下更新不反映在更新面板

<form id="frmQuestion" action="AddQuestion.aspx"> 
      <div class="panel"> 
      <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> 
       <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
       <ContentTemplate> 
       <div class="panel-body" style="max-height: 420;overflow-y: scroll; border:1px solid Blue"> 
     <asp:Repeater ID="rptQuestions" runat="server"> 
      <HeaderTemplate> 
       <table class="table" cellpadding="5px" cellspacing="10px" border="solid" id="tableQuestion"> 
        <tr style="color: Black; background-color: Teal; border: solid;"> 
         <th style="width: 20px">No.</th> 
         <th style="width: 100px">Question</th> 
         <th style="width: 40px">QuestionType</th> 
         <th style="width: 110px">Text Answer</th> 
         <th style="width: 100px">Multiple Choice 1</th> 
         <th style="width: 100px">Multiple Choice 2</th> 
         <th style="width: 100px">Multiple Choice 3</th> 
         <th style="width: 100px">Multiple Choice 4</th> 
         <th style="width: 70px">True/False</th> 
         <th>Controls</th> 
        </tr> 
      </HeaderTemplate> 
      <ItemTemplate> 
       <tr style="color: Black; background-color: Silver; border: solid;" id="trdata" class="trclass"> 

        <td id="no"> 
         <asp:Label runat="server" ID="lblNo" Text='<%#Eval("Qno") %>' /></td> 

        <td id="que"> 
         <asp:Label runat="server" ID="lblQuestion" Text='<%#Eval("Question") %>'></asp:Label> 
         <asp:TextBox runat="server" ID="txtQuestion" Text='<%#Eval("Question") %>' Visible="false"></asp:TextBox> 
         <asp:Label runat="server" ID="lblQid" Text='<%#Eval("Qid") %>'></asp:Label></td> 

        <td> 
         <asp:Label runat="server" ID="lblQtype" Text='<%#Eval("Qtype") %>'></asp:Label> 
         <asp:DropDownList runat="server" ID="ddlQType" Visible="false"></asp:DropDownList> 
         <%-- <select class="dropdown" id="ddlQType" name="ddlQType" style="width:100px" runat="server"> 
             <option value="0">--Select--</option> 
             <option value="1">Descriptive Answer</option> 
             <option value="2">Multiple Choice </option> 
             <option value="3">True/False answer</option></select>--%></td> 

        <td> 
         <asp:Label runat="server" ID="lblAnsDesc" Text='<%#Eval("description") %>' Width="100px"></asp:Label> 
         <asp:TextBox runat="server" ID="txtAnsDesc" Text='<%#Eval("description") %>' Width="100px" Visible="false"></asp:TextBox></td> 

        <td> 
         <asp:Label runat="server" ID="lblch1" Text='<%#Eval("choice1") %>' Width="100px"></asp:Label> 
         <asp:TextBox runat="server" ID="txtch1" Text='<%#Eval("choice1") %>' Width="100px" Visible="false"></asp:TextBox></td> 

        <td> 
         <asp:Label runat="server" ID="lblch2" Text='<%#Eval("choice2") %>' Width="100px"></asp:Label> 
         <asp:TextBox runat="server" ID="txtch2" Text='<%#Eval("choice2") %>' Width="100px" Visible="false"></asp:TextBox></td> 

        <td> 
         <asp:Label runat="server" ID="lblch3" Text='<%#Eval("choice3") %>' Width="100px"></asp:Label> 
         <asp:TextBox runat="server" ID="txtch3" Text='<%#Eval("choice3") %>' Width="100px" Visible="false"></asp:TextBox></td> 

        <td> 
         <asp:Label runat="server" ID="lblch4" Text='<%#Eval("choice4") %>' Width="100px"></asp:Label> 
         <asp:TextBox runat="server" ID="txtch4" Text='<%#Eval("choice4") %>' Width="100px" Visible="false"></asp:TextBox> 
         <asp:Label runat="server" ID="lblCorrect" Text='<%#Eval("correct") %>' /></td> 

        <td> 
         <asp:Label runat="server" ID="lblisTrue" Text='<%# Eval("isTrue") %>' Width="70px"></asp:Label> 
         <asp:CheckBox runat="server" ID="chkistrue" Checked='<%#(Eval("isTrue")=="true") %>' Width="70px" Visible="false" /></td> 

        <td><span class="more"> 
         <asp:LinkButton ID="lnkEdit" Text="Edit" runat="server" data-toggle="modal" data-target="#myModal" OnClientClick="getdata();" CausesValidation="false" /> 
         <asp:LinkButton ID="lnkDelete" Text="Delete" runat="server" OnClick="OnDelete" CausesValidation="false" OnClientClick="return confirm('Do you want to delete this row?');" /> 
        </span></td> 
       </tr> 
      </ItemTemplate> 
      <FooterTemplate> 
       </table> 
      </FooterTemplate> 
     </asp:Repeater> 

我的問題是,當我更新內部轉發的任何記錄。記錄被更新,數據庫表被更新,獲取的數據表顯示更新。 但該頁面不顯示更新。當我刷新頁面時,反映了更新。我不知道是什麼導致了這個問題。更新的服務器代碼是

protected void BindRepeater(int tid) 
{ 
    try 
    { 

     cmd = new SqlCommand("SP_GetQuestions", connection); 
     cmd.CommandType = CommandType.StoredProcedure; 
     cmd.Parameters.AddWithValue("@Tid", tid); 
     SqlDataAdapter sda = new SqlDataAdapter(cmd); 
     DataTable dt = new DataTable(); 

     sda.Fill(dt); 
     //connection.Close(); 
     if (dt.Rows.Count > 0) 
     { 
      //adding qno to dt 
      dt.Columns.Add("Qno", typeof(System.Int32)); 
      for (int i = 0; i < dt.Rows.Count; i++) 
      { 
       dt.Rows[i]["Qno"] = i + 1; 
      } 
      rptQuestions.DataSource = dt; 
      rptQuestions.DataBind(); 
     } 
    } 

    catch (Exception ex) 
    { 
     Response.Write(ex.Message); 
    } 
} 

protected Question getData() 
{ 
    Question question = new Question(); 
    question.questDesc = txtQuestionDesc.Text; 
    question.ansdesc = null; 
    question.ch1 = null; 
    question.ch2 = null; 
    question.ch3 = null; 
    question.ch4 = null; 
    question.correct = null; 
    //question.isTrue = null; 
    //question.qid = null; 
    //question.qtype = null; 
    question.qtype = Convert.ToInt32(ddlQType.Value); 
    switch (question.qtype) 
    { 
     case 1: 
      question.ansdesc = textareaAns.InnerText.ToString(); 
      break; 
     case 2: 
      question.ch1 = txtMulti1.Text; 
      question.ch2 = txtMulti2.Text; 
      question.ch3 = txtMulti3.Text; 
      question.ch4 = txtMulti4.Text; 
      question.correct = ""; 
      if (chkmulti1.Checked == true) 
       question.correct += "1"; 
      if (chkmulti2.Checked == true) 
       question.correct += "2"; 
      if (chkmulti3.Checked == true) 
       question.correct += "3"; 
      if (chkmulti4.Checked == true) 
       question.correct += "4"; 
      break; 
     case 3: 
      if (rbtrue.Checked == true) 
       question.isTrue = true; 
      if (rbfalse.Checked == true) 
       question.isTrue = false; 
      break; 
    } 
    return question; 
} 

protected void btnUpdate_Click(object sender, EventArgs e) 
{ 
    Question question = getData(); 
    question.qid = Convert.ToInt32(txtQuestid.Text.ToString()); 
    cmd = new SqlCommand("SP_UpdateQuestion", connection); 
    cmd.CommandType = CommandType.StoredProcedure; 
    cmd.Parameters.AddWithValue("@question", question.questDesc); 
    cmd.Parameters.AddWithValue("@qid", question.qid); 
    cmd.Parameters.AddWithValue("@ans", question.ansdesc); 
    cmd.Parameters.AddWithValue("@ch1", question.ch1); 
    cmd.Parameters.AddWithValue("@ch2", question.ch2); 
    cmd.Parameters.AddWithValue("@ch3", question.ch3); 
    cmd.Parameters.AddWithValue("@ch4", question.ch4); 
    cmd.Parameters.AddWithValue("@correct", question.correct); 
    cmd.Parameters.AddWithValue("@isTrue", question.isTrue); 
    cmd.Parameters.AddWithValue("@qtype", question.qtype); 
    try 
    { 
     connection.Open(); 
     cmd.ExecuteNonQuery(); 
     connection.Close(); 
     BindRepeater(Convert.ToInt32(Session["tid"])); 
     Response.Write("<script>alert('Question updated successfully!');</script>"); 
    } 
    catch (Exception ex) 
    { 
     Response.Write(ex.Message); 
    } 
} 

請告訴我如何解決這個問題。我甚至將update面板的updateMode屬性保留爲'conditional',但沒有結果。

回答

0

您是否檢查控制檯是否有錯誤?因爲您使用Response.WriteUpdatePanel。這會給你以下錯誤

Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.

於是刪除所有的Response.Write的代碼,如果你想顯示一個JavaScript警告,使用ScriptManager

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "showAlert", "alert('Question updated successfully!');", true);