Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6016907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:03:03+00:00 2026-05-23T03:03:03+00:00

I am trying to access a method in my code behind called Button1_Click using

  • 0

I am trying to access a method in my code behind called “Button1_Click” using Javascript, I think there is something wrong in my code below because currently I have to click twice in order for the method to trigger, one click doesn’t trigger the method.

My Test Code:

// Javascript

<script type="text/javascript">
 function CallMe() { document.getElementById('<%= ButtonHidden.ClientID %>').click(); }
</script>

// Markup

<asp:Button ID="ButtonVisible" runat="server" Text="Test Button"
  OnClientClick="CallMe();"/>
<asp:Button ID="Button1" runat="server" style="display:none;" Text="Click"
  OnClick="Button1_Click"/>

// Code Behind Method

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect("http://google.com");
}

Am I missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:03:03+00:00Added an answer on May 23, 2026 at 3:03 am

    Instead of using javascript why not simply assign the same server click handler for both buttons:

    <asp:Button 
        ID="ButtonVisible" 
        runat="server" 
        Text="Test Button" 
        OnClick="Button1_Click" />
    
    <asp:Button 
        ID="Button1" 
        runat="server" 
        style="display:none;" 
        Text="Click" 
        OnClick="Button1_Click" />
    

    UPDATE:

    A better solution would be to have your javascript function return a boolean value depending on whether some conditions are met which will execute the server handler:

    <script type="text/javascript">
        function CallMe() {         
            if (some condition) {
                return true; // allow the server to be called
            }
            return false;
        }
    </script>
    

    and then use both OnClick and OnClientClick on the button:

    <asp:Button 
        ID="ButtonVisible" 
        runat="server" 
        Text="Test Button" 
        OnClientClick="return CallMe();"
        OnClick="Button1_Click" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to find the method behind having superuser access on android devices. basically
After trying to access ivars using KVC, I have noticed that there was no
I'm getting a NoMethodError when trying to access a method defined in one of
I'm trying to access the Facebook API Admin.getMetrics method via jQuery. I'm correctly composing
I am trying to access the Cache in the Application_Start method of Global.asax. I
I am trying to access a REST webservice, however my code doesn't work and
I'm trying to call a method of the superclass by using a variable method
In C#, I am trying to PInvoke the following C method: // C code:
I am trying to access a web API using a POST technique. I AM
Not my code, trying to fix it at the 11th hour. Trying to access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.