Showing posts with label Button. Show all posts
Showing posts with label Button. Show all posts

Oct 28, 2013

Identify button Id in button click event handler

When you have multiple buttons more or like needed common handler, you can have the same handler for OnClick event like mentioned below.


<asp:LinkButton runat="server" ID="btnMonth" Text="Month" OnClick="btnView_Click" />

<asp:LinkButton runat="server" ID="btnWeek" Text="Week" OnClick="btnView_Click" />

<asp:LinkButton runat="server" ID="btnDay" Text="Day" OnClick="btnView_Click" />


Then, if needed you can find the button ID that user has clicked in the event handler like below.


 protected void btnView_Click(object sender, EventArgs e)
    {
      switch (((LinkButton)sender).ID)
      {
        case "btnWeek":
          // Do actions specific to btnWeek button click
          break;
        case "btnMonth":
          // Do actions specific to btnWeek button click
          break;
        case "btnDay":
          // Do actions specific to btnWeek button click
          break;
      }

      // Common Actions  
    }

Dec 30, 2010

ASP.Net Message Box Alert Display

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick = "return confirm('Are you sure you want to delete?');"/>   

How to Disable the Submit Button

If you want to prevent multiple clicks on a form submit button, disable the button.
It’s easy, simple. I’ll show you exactly how to do it.
Simply add the in the page load but in this the server isde code is not excuted

b1.Attributes.Add(

other wise try like this
<input

   type="submit"

   onclick="this.disabled=true;">
"onclick", "this.disabled=true;");

How to Disable the Submit Button and also run server code

If you want to prevent multiple clicks on a form submit button, disable the button.
It’s easy, simple. I’ll show you exactly how to do it.
Simply add the  in the page load

btnSubmit.Attributes.Add("onclick", ("javascript:" + btnSubmit.ClientID + ".disabled=true;") + Page.ClientScript.GetPostBackEventReference(btnSubmit, ""));