开发者

Disable save button in gridview

开发者 https://www.devze.com 2023-03-02 18:54 出处:网络
I have Save button as part of EditItemTemplate of the grid. on click of the button I want to disable the button to have a single click disable effect.

I have Save button as part of EditItemTemplate of the grid. on click of the button I want to disable the button to have a single click disable effect.

  1. I did try with javascript, in this case no server side code is executed.
  2. Added the attribute to the button, even this doesn't help
  3. Tried by adding UseSubmitBehavior="false" property too

Wh开发者_运维技巧at would be other possible solution to achieve this?


(Answered by in a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

Here is the solution:

  1. Set the UseSubmitBehavior="false" for the button in aspx page.

  2. In the .cs page, in the RowDataBound event write the following code:

///Grid row event RowDataBound
protected void gvr_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
       if ((e.Row.RowState & DataControlRowState.Edit) > 0)
       {
            ///Creating the Save button object
            Button btn = (Button)e.Row.Cells[6].FindControl("btnSave");

            ///Add the attribute to disblae the button
            btn.Attributes.Add("onclick", "this.disabled=true;");
       }
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消