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?
 
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
 
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
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
 
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
 
gabi456Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.