标签文本更新后未显示 [英] Label Text Not showing after Updation

查看:75
本文介绍了标签文本更新后未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在打开转发器上的Fancybox''行编辑linkBut​​ton n更新内容我想在执行更新查询后将标签文本显示为已更新。但是不知道这个代码的标签是错误的标签文本是更新后没有显示任何人可以帮助我吗?

提前感谢。



I''m Opening Fancybox on Repeater'' Row Edit linkButton n updating content i want to show label text as "Updated" after the execution of Update Query.But Don''t Know whats wrong with this code Label text is not showing after Updation can anyone help me out ?
thanks in advance.

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Thread.Sleep(3000);
        //foreach (RepeaterItem item2 in Repeater1.Items)
        //{
            TextBox name = (TextBox)e.Item.FindControl("TextBox1");
            TextBox address = (TextBox)e.Item.FindControl("TextBox2");
            //Label lbl = (Label)e.Item.FindControl("Label1");


            if (e.CommandName == "Edit")
            {
                int p_id = Convert.ToInt32(e.CommandArgument);
                SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=practice;integrated security=true;");
                SqlCommand sqlcomm = new SqlCommand("Update persons set p_name='" +name.Text +"' , p_address='" + address.Text + "'  where p_id='" + p_id + "'", sqlconn);
                sqlconn.Open();
                sqlcomm.ExecuteNonQuery();
                
                sqlconn.Close();
                //lbl.Text = "Updated";
                Label1.Text = "updated";
                
                
                Bind();
                

                
                


            }
            
            
        //}
        
    }





ASPX part-





ASPX part-

<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
        <asp:Repeater ID="Repeater1" runat="server" 

            onitemcommand="Repeater1_ItemCommand">
        
         <HeaderTemplate>
        <table cellpadding="5px" style="margin-removed600px;margin-removed200px">
       <th>ID</th><th>Name</th><th>Address</th><th>Edit</th>
        
        </HeaderTemplate>
        <ItemTemplate>
       <tr> <td><%#Eval("p_id") %></td><td><%#Eval("p_name") %></td><td><%#Eval("p_address") %></td><td>
           <asp:LinkButton ID="LinkButton1"  runat="server" class="modalbox" href="#inline"><img alt="" src="pencil.png" /></asp:LinkButton>
           
           
          <div id="inline">
              <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
             <ContentTemplate> 
          <table>
           <tr><td>Name</td><td>
               <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("p_name") %>'></asp:TextBox></td></tr>
             <tr><td>Address</td><td>
               <asp:TextBox ID="TextBox2" runat="server" Text='<%#Eval("p_address") %>'></asp:TextBox></td></tr>
             <tr><td>
                 </td><td>
                 
                 <asp:Button ID="Button1" runat="server" Text="Update" CommandName="Edit" CommandArgument='<%#Eval("p_id") %>'/></td></tr>
                 <tr>
                 <br />
              <asp:UpdateProgress ID="UpdateProgress1" runat="server">
              <ProgressTemplate>
              <%--<img src="ajaxgif.gif" />--%>
              Updating...
              
              </ProgressTemplate>
              </asp:UpdateProgress>
                        <tr><asp:Label ID="Label1" runat="server"></asp:Label></tr>

              </tr>
              
          </table>
          </ContentTemplate>
          </asp:UpdatePanel>
          </div>
          
          
           
           </td></tr>
        
        </ItemTemplate>
        <FooterTemplate>
        
         </table>
        
        </FooterTemplate>
        
        
        
        </asp:Repeater>

推荐答案

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
   Thread.Sleep(3000);        
   TextBox name = (TextBox)e.Item.FindControl("TextBox1");
   TextBox address = (TextBox)e.Item.FindControl("TextBox2");
   Label lbl = (Label)e.Item.FindControl("Label1"); 
   if (e.CommandName == "Edit")
   {
      int p_id = Convert.ToInt32(e.CommandArgument);
      SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=practice;integrated security=true;");
                SqlCommand sqlcomm = new SqlCommand("Update persons set p_name='" +name.Text +"' , p_address='" + address.Text + "'  where p_id='" + p_id + "'", sqlconn);
      sqlconn.Open();
      sqlcomm.ExecuteNonQuery();
      sqlconn.Close();
      lbl.Text = "Updated";       
   }                             
}

//Don't Call Your Bind() Method In ItemCommand Event and Call it In Your Page_Load With IspostBack=false
//In Page_Load
If(!IsPostBack)
{
   Bind();//Use it!....
}          






您已将Label1放在更新面板之外,并从更新面板内部引发事件。因此标签的文本已更改,但在客户端没有刷新。



因此解决方案是您必须将标签放在更新面板中。



还有一个建议,而不是将更新面板放在ItemTemplate中,将Repeater控件本身放在更新面板中。

有很多更新页面中的面板也不是一个好习惯。





希望这会对你有所帮助。



-Gayatri
Hi,

You have placed Label1 Outside of the update panel and the event is raised from inside the update panel. So the label''s text is changed but it is not refreshed on the client side.

So the solution is You have to put the label inside the update panel.

Also one more suggestion, instead of putting update panel inside ItemTemplate, put the Repeater control itself inside the update panel.
Having lots of update panels in a page is also not a good practice.


Hope this helps you.

-Gayatri


这篇关于标签文本更新后未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆