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

gabi456Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rahul GadeSr. ArchitectCommented:

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
0
gabi456Author Commented:
Hello Rahul

Sorry, it didn't work.

I want it be when it is posted back, but not from the radiobuttonlist control.

Thanks
0
Rahul GadeSr. ArchitectCommented:

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
0
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Rahul GadeSr. ArchitectCommented:
Instead of registerScriptBlock, you can also use page.registerStartupScript function to immediatly reflect the script code.

0
gabi456Author Commented:
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.
0
dejaanbuCommented:
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
0
Rahul GadeSr. ArchitectCommented:
Ok, in case you have multiple places on page causing the postBack and you want to restrict function invokation only for a specific condition, then you can use hidden control like textbox to maintain the flag. You can set the value of this flag using javascript, while you will have to retrive this value on server side using request object as this textbox won't be a server side control.

While, I still belive you can achive the same using registerStartupScript and IsPostBack (there are different ways to detect the same). But for multiple location causing the similar async post back situation, hidden control should do the trick for you.

-Rahul
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gabi456Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.