gabi456
asked on
Ajax postback control pageload function
Hello
In the code attached, there is a function which disables some buttons.
What is needed is that this function not be called if the postback comes from an asp.net radiobuttonlist that is inside a listview.
Or another would be to only call this function first time the listview is loaded and not when further ajax postbacks are done after e.g. selection an item in the radiobuttonlist (which calls a SelectedIndexChanged in the code behind).
In the code attached, there is a function which disables some buttons.
What is needed is that this function not be called if the postback comes from an asp.net radiobuttonlist that is inside a listview.
Or another would be to only call this function first time the listview is loaded and not when further ajax postbacks are done after e.g. selection an item in the radiobuttonlist (which calls a SelectedIndexChanged in the code behind).
function pageLoad() {
var manager = Sys.WebForms.PageRequestManager.getInstance();
manager.add_endRequest(OnEndRequest);
var elem = document.getElementById('<%= DataPagerListView.ClientID %>').getElementsByTagName("*");
for (var i = 0; i < elem.length; i++) {
if (!elem[1].disabled) {
disable();
}
}
}
ASKER
Hello Rahul
Sorry, it didn't work.
I want it be when it is posted back, but not from the radiobuttonlist control.
Thanks
Sorry, it didn't work.
I want it be when it is posted back, but not from the radiobuttonlist control.
Thanks
Ohh, sorry I didn't realized that you want to apply this restriction on client side code, page.IsPostBack is available on code behind only.
In order to have better control on what script should be executed when loading page you can use page.registerScriptBlock("
So, you can register your javascript code only when needed at runtime (page loading), instead of having this as a part of page always.
-Rahul Gade
Instead of registerScriptBlock, you can also use page.registerStartupScript function to immediatly reflect the script code.
ASKER
Hello
This still doesn't solve the problem. Even if i register the script from the code behind it will still run when the radiobuttonlist is selected.
Need to put something in the javascript script code attached to not call the function if the postback was done from the radiobuttom list selectedindexchanged event.
Thanks.
This still doesn't solve the problem. Even if i register the script from the code behind it will still run when the radiobuttonlist is selected.
Need to put something in the javascript script code attached to not call the function if the postback was done from the radiobuttom list selectedindexchanged event.
Thanks.
before registering the script, you just check which control causes the postback, if the postback is raised from the radiobutton, then do not register the script.
here is a method to findout which control causes the postback
http://stackoverflow.com/questions/3175513/on-postback-how-can-i-check-which-control-cause-postback-in-page-init-event
here is a method to findout which control causes the postback
http://stackoverflow.com/questions/3175513/on-postback-how-can-i-check-which-control-cause-postback-in-page-init-event
check this link also for detecting this in javascript
http://www.aspsnippets.com/Articles/Detect-ASP.Net-Asynchronous-PostBack-using-PageRequestManager-Events-in-JavaScript.aspx
http://www.aspsnippets.com/Articles/Detect-ASP.Net-Asynchronous-PostBack-using-PageRequestManager-Events-in-JavaScript.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
You need to add a condition in the pageLoad() as
if ( ! Page.isPostBack)
{
//Put the code that you do not want to get executed for ajax postback
}
-Rahul Gade