I have this solution for a single button:
myButton.Attributes.Add("onclick", "this.disabled=true;" + GetPostBackEventReference(myButton).ToString());
Which works pretty well for one button, any ideas on how to expand this to 2 buttons?
I have this solution for a single button:
myButton.Attributes.Add("onclick", "this.disabled=true;" + GetPostBackEventReference(myButton).ToString());
Which works pretty well for one button, any ideas on how to expand this to 2 buttons?
You could add an clientside onSubmit handler, or you could do this:
myButton.Attributes.Add("onclick", "this.disabled=true; document.getElementById('"
+ button2.ClientID + "').disabled = true;"
+ GetPostBackEventReference(myButton).ToString());
change the command to:
myButton.Attributes.Add("onclick", "this.disabled=true;document.getElementbyID("Button2").disabled=true;" + GetPostBackEventReference(myButton).ToString());
Change the javascript to reference the other button as well.
var btn1 = document.GetElementById('btn1ID');
var btn2 = this;
btn1.disabled = true;
btn2.disabled = true;
If the buttons are in a naming container, you'll need to use the .NET object's property called ClientID to get the html ID of the element.
var btn1 = document.GetElementById('<%= btn1.ClientID %>');
I suggest wrapping these in a script tag and a function, then just call the function from your .NET attribute addition.
CodeBehind
btn2.Attributes.Add("onclick", "handleClick();")
ASPX
<script type="text/javascript">
function handleClick() {
var btn1 = document.GetElementById('<%= btn1.ClientID %>');
var btn2 = this;
btn1.disabled = true;
btn2.disabled = true;
}
</script>
<asp:Button id="btn1" runat="server" text="Button 1" />
<asp:Button id="btn2" runat="server" text="Button 2" />