Connecting Tech Pros Worldwide Help | Site Map

force asp button click event

Newbie
 
Join Date: Oct 2007
Posts: 31
#1: Oct 15 '08
hi,
im dveloping a web system using vs 2008. in my page i have a ajax page method wich is called by javascript function . in onsuceeded method i want to force the save button on my page to be called and do the serverside finction in code behind "btnSave_Click(object sender, EventArgs e)" method.

I am calling this pagemethod function in onclientclick event of the save button.

depending on the result from the server side which is stored in result parameter which is passed to onsuceeded method, i want to call the "click" event of the save button.

how to call this click event of the buton using javascript?
Member
 
Join Date: Oct 2008
Location: USA
Posts: 55
#2: Oct 16 '08

re: force asp button click event


as far as I know you can't fire an actual user event using javascript.

To elaborate:
you can call any event on any object AS a function e.g.

Expand|Select|Wrap|Line Numbers
  1. myEl.onmousedown()
but the default functionality of the click will not fire.

select boxes for instance will not open just because you fire the event on them, but if you set a function on the selectbox, that function will fire, but the selectbox will still not open.
Newbie
 
Join Date: Oct 2007
Posts: 31
#3: Oct 16 '08

re: force asp button click event


hi,
I tried with document.getElementById("<%=btnSave.ClientID%>").c lick();

but it is not working..

I am using masterpage in my system.
Member
 
Join Date: Oct 2008
Location: USA
Posts: 55
#4: Oct 16 '08

re: force asp button click event


try onclick() first of all, but like I was saying before...if this is a submit button for a form or something, the default functionality will not fire when you call it, you can only fire events that you have bound written functions to
Newbie
 
Join Date: Oct 2007
Posts: 31
#5: Oct 16 '08

re: force asp button click event


ok. i found the solution.

in my onsucceeded method i put

var btnName=$get("<%=btnSave.ClientID%>").name;
__doPostBack(btnName,"");

this fires the onClick serverside function .
Reply