Hi, I
I have written a javascript file as
Sys.Application.add_load(ApplicationLoadHandler)
function ApplicationLoadHandler(sender, args){
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckStatus);
}
function CheckStatus(sender, args){
var prm = Sys.WebForms.PageRequestManager.getInstance();if (prm.get_isInAsyncPostBack() & args.get_postBackElement().id =='CancelRefresh'){
alert('cancelling');prm.abortPostBack();
alert('cancelled');}
}
if(typeof(Sys) !=="undefined") Sys.Application.notifyScriptLoaded();----------------
I have written this to cancel my dropdown list postback But request is not cancelling.
My .aspx code.. is
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server">
<Scripts>
<asp:ScriptReferencePath="Cancel.js"/>
</Scripts>
</asp:ScriptManager>
<div>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:DropDownListrunat="server"ID="ddl_testing"OnSelectedIndexChanged="ddl_testing_SelectedIndexChanged"AutoPostBack="True">
<asp:ListItemText="Manoj"></asp:ListItem>
<asp:ListItemText="Atul"></asp:ListItem>
<asp:ListItemText="Punit"></asp:ListItem>
</asp:DropDownList>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label><br/>
<br/>
<asp:ButtonID="CancelRefresh"runat="server"Text="Cancel"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
While my .cs code is as follow..
protectedvoid Page_Load(object sender,EventArgs e)
{
Label1.Text = ddl_testing.SelectedItem.Text;
}
protectedvoid ddl_testing_SelectedIndexChanged(object sender,EventArgs e){
System.Threading.Thread.Sleep(2000);Label1.Text = ddl_testing.SelectedItem.Text.ToString();
}
}
But my ajax request is not cancelling on clikcking cancel button ..Can anybody tell me why..
Thanks in advance..
Since the Cancel button resides in the UpdatePanel it appends the NamingContainer in the ID.
Try indexof instead of exatct match:
args.get_postBackElement().id.indexOf ('CancelRefresh') > -1
No comments:
Post a Comment