I have a visual web part that has an update panel that has a button that performs an action. I want to prevent users from hitting that button more than once.
The solutions I found use javascript to disable the button then do the postback.
The problem with this that I am having is that my buttonclick method is getting called 2 times since it seems to go to Page_Load 2 times.
Here is my code. First the button and javascript then the Page_Load method.
<script type="text/javascript">
function DisableButton() {
document.getElementById('<%= BetOnCar.ClientID %>').disabled = "disabled";
__doPostBack('<%= BetOnCar.ClientID %>', '');
}
</script>
<asp:Button ID="BetOnCar" runat="server" Text="Bet" OnClientClick="DisableButton();" onclick="BetOnCar_Click" Enabled="false" />
protected void Page_Load(object sender, EventArgs e)
{
string controlName = this.Page.Request["__EVENTTARGET"];
if (BetOnCar.ClientID == this.Page.Request["__EVENTTARGET"])
{
BetOnCar_Click(sender, e);
}
}
I'm hoping that I am doing this type of thing in the wrong location because it seems like page_load gets hit more often than I expected.