I am trying to disable a button after the request begins and then enable when the request ends. I've gotten the disable part to work but it does not enable it. What am i doing wrong? Here is my code.
Thanks.
<formid="form1"runat="server">
<ajaxToolkit:ToolkitScriptManagerrunat="server"ID="ToolkitScriptManager1"EnableScriptGlobalization="true"EnableScriptLocalization="true"></ajaxToolkit:ToolkitScriptManager>
<scripttype="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(HideButton);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ShowButton);
function ShowButton()
{
$get("Button1").disabled ="false";}
function HideButton(){
$get("Button1").disabled ="true";}
</script>
<div>
<ajax:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:ButtonID="Button1"runat="server"Text="Button"OnClick="Button1_Click"/>
<asp:LabelID="lblTest"runat="server"></asp:Label>
</ContentTemplate>
</ajax:UpdatePanel>
<ajax:UpdateProgressID="UpdateProgress1"runat="server"AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
processing.....
</ProgressTemplate>
</ajax:UpdateProgress>
</div>
</form>
Hi Azminer,
My understanding of your issue is that the button you disabled when beginRequest event is fired cannot be enabled when the partial-update finished. If I ahve misunderstood you , please feel free to let me know.
I think your problem is caused by this sentence ($get("Button1").disabled ="false") that you have assigned a string value to a bool variable. Here is my sample:
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(HideButton);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ShowButton);
function ShowButton(){
$get("<%=Button1.ClientID %>").disabled = false;
}
function HideButton(){
$get("<%=Button1.ClientID %>").disabled = true;
}
</script>
By the way, in your situation, you can get the same result without doing anything in endRequest event since the elements inside the UpdatePanel has been refreshed.
Best Regards,
Jonathan
Thanks Jonathan!
No comments:
Post a Comment