How to call button click event from div onclick event?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saadkhan
    New Member
    • Aug 2008
    • 40

    How to call button click event from div onclick event?

    i want to a buttin click event when a <div> is clicked. That is when div tag`s onclick event fires, it directs to button click event.....

    <div id="Div" onclick="?????? ??">
    HEADER
    </div>



    whereas my button`s click event is:
    protected void myButton_Click( object sender, EventArgs e)
    {

    }
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    1- this doesn't look like it uses ASP (file extension .asp). Is this asp.net (.aspx)? Let me know, and I will get this post in the right forum.

    2- The name doesn't have to match, just set the div's onclick attribute (possibly called something else, like "leftmousebutto nup") to myButton_Click.

    Let me know if this helps.

    Jared

    Comment

    • saadkhan
      New Member
      • Aug 2008
      • 40

      #3
      yeah its aspx file code. I`v just putted in the required n relevant code. thts y i guess u got confused abt it...lolz
      anyways now can u guide me plz

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Code:
        <div onclick="myButton_Click"></div>

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          Originally posted by jhardman
          Code:
          <div onclick="myButton_Click"></div>
          Not going to work. That is a server method that he's posted, not a client one. If you do that, it will be looking for some JavaScript function called myButton_Click.

          Sadly, I don't have your answer. One option may be to set a hidden value and trigger a postback by submitting the form through javascript, and in the page_load testing for that value. if it is there, call your button's method.

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            Originally posted by insertAlias
            Not going to work. That is a server method that he's posted, not a client one. If you do that, it will be looking for some JavaScript function called myButton_Click.

            Sadly, I don't have your answer. One option may be to set a hidden value and trigger a postback by submitting the form through javascript, and in the page_load testing for that value. if it is there, call your button's method.
            I guess that makes sense, but then how does one fire a server-side event from onclick in the first place?

            Comment

            Working...