Post back using javascript

G

Garg

I had a listbox, whose autoPostBAck property was set to true. So. if
I was clicking on any item for the first time, it caused a successful
post-back. However, if i clicked on the item subsequently, no post-
back occured (because the index of the selected item did not change,
hence the click event was not captured).

So, to capture the click event everytime, i added a _dopostback
function in javascript code. This made post-back possible for
subsequent clicks on the same list-item.


But i get a problem because of this. Now when I click on a list-item
first time, post-back occurs twice:
-- Once because of javascript function (_dopostback)
-- Secondly, because of autoPostBack property of list-box set to
true.


However, on second click, there occurs only one post-back because of
javascript only. Thats wat I require. Wat i dont require is two post-
backs on first click!!!


Pls tell me how do I prevent javascript function from working on
first
click of the list-item???
 
A

Alexey Smirnov

I had a listbox, whose autoPostBAck property was set to true. So. if
I was clicking on any item for the first time, it caused a successful
post-back. However, if i clicked on the item subsequently, no post-
back occured (because the index of the selected item did not change,
hence the click event was not captured).

So, to capture the click event everytime, i added a _dopostback
function in javascript code. This made post-back possible for
subsequent clicks on the same list-item.

But i get a problem because of this. Now when I click on a list-item
first time, post-back occurs twice:
-- Once because of javascript function (_dopostback)
-- Secondly, because of autoPostBack property of list-box set to
true.

However, on second click, there occurs only one post-back because of
javascript only. Thats wat I require. Wat i dont require is two post-
backs on first click!!!

Pls tell me how do I prevent javascript function from working on
first
click of the list-item???

At least you can try the following: remember the value of the listbox,
and when an onChange event occurred check if the value has been
changed. When value is changed, do nothing. When it is not changed do
a postback.

Some thoughts:

<asp:DropDownList id="'listboxid'"
onchange="javascript:if(this.options[this.selectedIndex].value==v1)
_dopostback;"....

<script>
var v1 =
document.getElementById('listboxid').options[document.getElementById('listboxid').selectedIndex].value;
</script>
 
V

Veerle

I had a listbox, whose autoPostBAck property was set to true. So. if
I was clicking on any item for the first time, it caused a successful
post-back. However, if i clicked on the item subsequently, no post-
back occured (because the index of the selected item did not change,
hence the click event was not captured).

So, to capture the click event everytime, i added a _dopostback
function in javascript code. This made post-back possible for
subsequent clicks on the same list-item.

But i get a problem because of this. Now when I click on a list-item
first time, post-back occurs twice:
-- Once because of javascript function (_dopostback)
-- Secondly, because of autoPostBack property of list-box set to
true.

However, on second click, there occurs only one post-back because of
javascript only. Thats wat I require. Wat i dont require is two post-
backs on first click!!!

Pls tell me how do I prevent javascript function from working on
first
click of the list-item???

Why not set the autopostback to false? Then only your javascript will
do its work and you'll get a single postback each time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top