Link to home
Start Free TrialLog in
Avatar of Mymail cpn
Mymail cpn

asked on

JQuery Detecting page post back

Hello,

How can I detect the page post back in my JQuery.

I am using Visual Studio 2015 with JQuery.

Scenario: I am populating my dropdown on the page using JQuery. But it needs to be done only once.
At present it is doing on every post back. So I can I check the page post back with JQuery?
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

You can check to see if the drop down is populated using jQuery.

if ($('#myDropDownList option').length === 0) {
    //load options
}

Open in new window


Or, set a hidden field on postback and check if that field has a value in jQuery before you populate the drop down.
Avatar of Mymail cpn
Mymail cpn

ASKER

Hello, I would like to verify the length as you suggested. But the syntax is throwing error.

I am trying to select my dropdown as

 $('[id*=DDList1]').append("CityName");

How do I check for length of my Dropdown?
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America 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 Julian Hansen
At present it is doing on every post back. So I can I check the page post back with JQuery?
Can you show us your code?
I am confused by what you mean it is populating on every post-back? Is the jQuery in the post-back code? Why would it run on each post back.

Obvious answer is move your jQuery outside of whatever is being refreshed by the post back and then you don't have to detect anything.
Thank you very much.
Your help is greatly appreciate.