Link to home
Start Free TrialLog in
Avatar of gabi456
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).
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();
                }

            }

        }

Open in new window

Avatar of Rahul Gade
Rahul Gade
Flag of India image


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
Avatar of gabi456
gabi456

ASKER

Hello Rahul

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("AA","<script langauge=JavaScript>your script goes here</script>.

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.

Avatar of gabi456

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.
Avatar of Deja Anbu
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
ASKER CERTIFIED SOLUTION
Avatar of Rahul Gade
Rahul Gade
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gabi456

ASKER

Thanks