force asp button click event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anudu
    New Member
    • Oct 2007
    • 31

    force asp button click event

    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?
  • zaphod42
    New Member
    • Oct 2008
    • 55

    #2
    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.

    Code:
    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.

    Comment

    • anudu
      New Member
      • Oct 2007
      • 31

      #3
      hi,
      I tried with document.getEle mentById("<%=bt nSave.ClientID% >").click();

      but it is not working..

      I am using masterpage in my system.

      Comment

      • zaphod42
        New Member
        • Oct 2008
        • 55

        #4
        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

        Comment

        • anudu
          New Member
          • Oct 2007
          • 31

          #5
          ok. i found the solution.

          in my onsucceeded method i put

          var btnName=$get("< %=btnSave.Clien tID%>").name;
          __doPostBack(bt nName,"");

          this fires the onClick serverside function .

          Comment

          Working...