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 6189845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:29:04+00:00 2026-05-24T02:29:04+00:00

I have a web project in C#/asp.net. I have a UserControl with a GridView

  • 0

I have a web project in C#/asp.net. I have a UserControl with a GridView that has a Button coded into it. The button has an OnClick event which will result in it a redirect to another page. At this point in time, the onclick event never happens no matter how many times I press the button. However, if I hardcode a button into the page that is using the user control (with the event in its code behind), the onclick events work perfectly fine.

Also, when I move the button outside of the UserControl’s GridView, it works fine. However, I am limited by space and need it to be placed in the pager bar along the bottom of the page.

<PagerTemplate>
     <table width="100%" cellpadding="0" cellspacing="0">
        <tr>
           <td align="left" valign="middle">
              <asp:Panel cssClass="PagerPanel" runat="server">
                 <asp:Button ID="FirstButton" runat="server" OnClick="FirstButton_Click" Text="|&lt;"  Enabled="<%# (_gridView.PageIndex > 0) %>" />
                 <asp:Button ID="PrevButton" runat="server" OnClick="PrevButton_Click" Text="&lt;" Enabled="<%# (_gridView.PageIndex > 0) %>" />
                 <%# _gridView.PageIndex+1  %> of <%# _gridView.PageCount %>
                 <asp:Button ID="NextButton" runat="server" OnClick="NextButton_Click" Text="&gt;" Enabled="<%# (_gridView.PageIndex < _gridView.PageCount-1) %>" />
                 <asp:Button ID="LastButton" runat="server" OnClick="LastButton_Click" Text="&gt;|" Enabled="<%# (_gridView.PageIndex < _gridView.PageCount-1) %>" />
              </asp:Panel>
           </td>

           <td>
           <asp:Button ID="Button1" OnClick="AddButton_Click" runat="server"       
              Text="Button" />
           </td>
        </tr>
     </table>
  </PagerTemplate>

UserControl Code Behind:

protected void AddButton_Click(object sender, EventArgs e)
{
    Response.Redirect("thisurl...");
}

Not sure what else I can do to handle this click event. Apparently the GridView is stopping it from firing somehow. Is there anyway that a UserControl’s GridView can have a button that will handle onclick events?

  • 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-24T02:29:04+00:00Added an answer on May 24, 2026 at 2:29 am

    You should add CommandName=”Button” attribute to the asp:Button declaration and then wire up the the RowCommand event of the GridView. Then, check for command name (i.e. if (e.CommandName == “Button”) in the OnRowCommand event handler.

    <asp:Button ID="Button1" CommandName="Button" runat="server" Text="Button" />
    

    …

    protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      if (e.CommandName == "Button")
      {
        ...
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UserControl in my Asp.net project that has a public property. I
I have an ASP.NET VB.NET web project that references a VB.NET class library. I
I have built a web setup project in VS2008 which installs my ASP.NET/Silverlight app
I have an ASP.NET web application project which references another project called ModusCore (or
I have a really simple ASP.NET web application and a web setup project that
I have a web project in asp.net in which i have dashboard on which
I am using an ASP.Net Web Application project. I have a user control which
The Scenario I have an ASP.Net Web Project that uses a master page. This
I have an asp.net web project which uses a SqlProfileProvider for membership structure,i am
I have an Asp.Net 4.0 Web Forms project that uses url routing for user

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.