Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Can we force to make button click event happen without actually clicking?

Can we force to make button click event happen without actually clicking?

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sudevsu
    wrote on last edited by
    #1

    Hello Experts, I have a Textbox and a button below it. In that Textbox, I am passing a session value and I want to make that button click event occur without actually clicking it. Is that possible? If Yes How? Can you please tell me with sample code or tutorial?

    Your help is much appreciated. Thanks Happy Coding!

    F D 2 Replies Last reply
    0
    • S sudevsu

      Hello Experts, I have a Textbox and a button below it. In that Textbox, I am passing a session value and I want to make that button click event occur without actually clicking it. Is that possible? If Yes How? Can you please tell me with sample code or tutorial?

      Your help is much appreciated. Thanks Happy Coding!

      F Offline
      F Offline
      F ES Sitecore
      wrote on last edited by
      #2

      The server click event or the client click event? What do you want to trigger the event? Is this web forms? MVC? You can just call the click event in js on some event and it'll work, but you've not given enough information to go on, but look at this to get you started http://api.jquery.com/click/[^]

      S 2 Replies Last reply
      0
      • F F ES Sitecore

        The server click event or the client click event? What do you want to trigger the event? Is this web forms? MVC? You can just call the click event in js on some event and it'll work, but you've not given enough information to go on, but look at this to get you started http://api.jquery.com/click/[^]

        S Offline
        S Offline
        sudevsu
        wrote on last edited by
        #3

        ASP web forms. please tell me how to do

        Your help is much appreciated. Thanks Happy Coding!

        1 Reply Last reply
        0
        • F F ES Sitecore

          The server click event or the client click event? What do you want to trigger the event? Is this web forms? MVC? You can just call the click event in js on some event and it'll work, but you've not given enough information to go on, but look at this to get you started http://api.jquery.com/click/[^]

          S Offline
          S Offline
          sudevsu
          wrote on last edited by
          #4

          button is in ASP web form. I want that event to happen before user clicks on it.

          Your help is much appreciated. Thanks Happy Coding!

          F 1 Reply Last reply
          0
          • S sudevsu

            button is in ASP web form. I want that event to happen before user clicks on it.

            Your help is much appreciated. Thanks Happy Coding!

            F Offline
            F Offline
            F ES Sitecore
            wrote on last edited by
            #5

            <html xmlns="http://www.w3.org/1999/xhtml">
            <head runat="server">
            <title></title>
            <script src="//code.jquery.com/jquery-1.10.2.js"></script>

            </head>
            <body>
            <form id="form1" runat="server">
            <asp:TextBox ID="Text1" runat="server" />
            <asp:Button ID="Button1" OnClick="Button1_Click" Text="Click" runat="server" />

                <script type="text/javascript">
                    $(document).ready(function () {
                        // click the button on page load
                        // $("#<%=Button1.ClientID%>").click();
            
                        // or click the button when the textbox loses focus
                        $("#<%=Text1.ClientID%>").blur(function () {
                            $("#<%=Button1.ClientID%>").click();
                        });
                    });
                </script>
            
            </form>
            

            </body>
            </html>

            S 1 Reply Last reply
            0
            • F F ES Sitecore

              <html xmlns="http://www.w3.org/1999/xhtml">
              <head runat="server">
              <title></title>
              <script src="//code.jquery.com/jquery-1.10.2.js"></script>

              </head>
              <body>
              <form id="form1" runat="server">
              <asp:TextBox ID="Text1" runat="server" />
              <asp:Button ID="Button1" OnClick="Button1_Click" Text="Click" runat="server" />

                  <script type="text/javascript">
                      $(document).ready(function () {
                          // click the button on page load
                          // $("#<%=Button1.ClientID%>").click();
              
                          // or click the button when the textbox loses focus
                          $("#<%=Text1.ClientID%>").blur(function () {
                              $("#<%=Button1.ClientID%>").click();
                          });
                      });
                  </script>
              
              </form>
              

              </body>
              </html>

              S Offline
              S Offline
              sudevsu
              wrote on last edited by
              #6

              My both the buttons are not in same.

              <form id="TireQuickSearch" method="post" action="DealerTireSearchResults.aspx" onsubmit="return ValidateTireQuickSearch(this);">
              <input type="hidden" name="FormAction" value="TireQuickSearch" />
              <input type="hidden" name="SortOrder" value="<asp:Literal id='litSortOrderDescription' runat='server' /> />
              <label> <input type="text" name="TireQuickSearch" id="PART#" class="tf1" value="<asp:Literal id='litTireQuickSearch' runat='server' /> />
              </label>
              <input name="SearchButton" type="image" src="images/btn_tireSearchADV-dim.jpg" disabled="disabled" /><br />
              </form>

              On the below button click I want my above Button click action to happen

              <asp:Button ID="btnSubmit" runat="server" Text="Submit" />

              Your help is much appreciated. Thanks Happy Coding!

              F 1 Reply Last reply
              0
              • S sudevsu

                My both the buttons are not in same.

                <form id="TireQuickSearch" method="post" action="DealerTireSearchResults.aspx" onsubmit="return ValidateTireQuickSearch(this);">
                <input type="hidden" name="FormAction" value="TireQuickSearch" />
                <input type="hidden" name="SortOrder" value="<asp:Literal id='litSortOrderDescription' runat='server' /> />
                <label> <input type="text" name="TireQuickSearch" id="PART#" class="tf1" value="<asp:Literal id='litTireQuickSearch' runat='server' /> />
                </label>
                <input name="SearchButton" type="image" src="images/btn_tireSearchADV-dim.jpg" disabled="disabled" /><br />
                </form>

                On the below button click I want my above Button click action to happen

                <asp:Button ID="btnSubmit" runat="server" Text="Submit" />

                Your help is much appreciated. Thanks Happy Coding!

                F Offline
                F Offline
                F ES Sitecore
                wrote on last edited by
                #7

                <asp:Button ID="Button1" Text="Click" runat="server" OnClientClick="return doSearch();" />

                <script type="text/javascript">
                function doSearch()
                {
                // this will not work if the button is disabled as in your example
                //$("[name='SearchButton'").click();

                    // can submit the form instead
                    $("#TireQuickSearch").submit();
                
                    return false;
                }
                
                S 2 Replies Last reply
                0
                • F F ES Sitecore

                  <asp:Button ID="Button1" Text="Click" runat="server" OnClientClick="return doSearch();" />

                  <script type="text/javascript">
                  function doSearch()
                  {
                  // this will not work if the button is disabled as in your example
                  //$("[name='SearchButton'").click();

                      // can submit the form instead
                      $("#TireQuickSearch").submit();
                  
                      return false;
                  }
                  
                  S Offline
                  S Offline
                  sudevsu
                  wrote on last edited by
                  #8

                  Thank you F-ES Sitecore. Is there anyway I can assign session value from same JQuery?

                  Your help is much appreciated. Thanks Happy Coding!

                  1 Reply Last reply
                  0
                  • F F ES Sitecore

                    <asp:Button ID="Button1" Text="Click" runat="server" OnClientClick="return doSearch();" />

                    <script type="text/javascript">
                    function doSearch()
                    {
                    // this will not work if the button is disabled as in your example
                    //$("[name='SearchButton'").click();

                        // can submit the form instead
                        $("#TireQuickSearch").submit();
                    
                        return false;
                    }
                    
                    S Offline
                    S Offline
                    sudevsu
                    wrote on last edited by
                    #9

                    Thank you :)

                    Your help is much appreciated. Thanks Happy Coding!

                    1 Reply Last reply
                    0
                    • S sudevsu

                      Hello Experts, I have a Textbox and a button below it. In that Textbox, I am passing a session value and I want to make that button click event occur without actually clicking it. Is that possible? If Yes How? Can you please tell me with sample code or tutorial?

                      Your help is much appreciated. Thanks Happy Coding!

                      D Offline
                      D Offline
                      deepankarbhatnagar
                      wrote on last edited by
                      #10

                      Yes it is possible. suppose your button name is btnAdd and you want btnAdd_click() event fire automatically on page load (suppose) , so on pageload call btnAdd_Click() like this: btnAdd_Click(this, null); This will fire the event of btnAdd_Click() without actually clicked.

                      hi

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups