Refresh an updatepanel on buttonclick from code-behind

后端 未结 3 1193
逝去的感伤
逝去的感伤 2021-01-21 15:51

I\'m using a Gridview that is using datasource & databinding. When i reload the page the gridview is updated but I want it to be on the buttonclick, but it\'s not working fo

3条回答
  •  生来不讨喜
    2021-01-21 16:58

    By default, partial-page updates are enabled in an update panel because the default value of the EnablePartialRendering property of the ScriptManager control is true.Putting the button in the update panel is suffice to give you what you need since the button acts as an asynchronus postback control inside the panel.Then just add this line( gvWallospts.Databind()) after your update.Let me know how it goes.

    protected void btnWall_Click(object sender, EventArgs e)
    {
        con.SendWallPost(con.GetId(Membership.GetUser().UserName), Convert.ToInt32(Request.QueryString["ID"]), txtWall.Text); //This method is sending the post
        //upWall.Update();
        gvWallPosts.DataBind();
    }
    

    Try setting up you markup like this

      
       
          
        
            
            
        
       
         
                
                    
                        <%# GetSender((int)Eval("WallSender"))%>
                        
    <%# Eval("Post")%>

    In your grid Row updating event

      protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    
    
        con.SendWallPost(con.GetId(Membership.GetUser().UserName),    Convert.ToInt32(Request.QueryString["ID"]), txtWall.Text); 
         gvWallPosts.DataBind();
    
    
    }
    

    Make sure that also you Binding code in page load is sandwiched by this

     If(!IsPostBack)
         {
                       }
    

提交回复
热议问题