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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:19:09+00:00 2026-06-06T15:19:09+00:00

I have a grid view in my main page and I display some data

  • 0

I have a grid view in my main page and I display some data for user(using BindGrid method).this grid view has some command buttons for each row that perform some operation like Update. when user clicks on update button I show to him/her a user control to update values.and when user clicks on update I want grid bind to new data(I want call BindGrid for new data). How I can do this and call a method in main page from user control?

Edit 1)

I wrote this code for user control:

public partial class SomeUserControl : System.Web.UI.UserControl
{
public event EventHandler StatusUpdated;

private void FunctionThatRaisesEvent()
{
    if (this.StatusUpdated != null)
        this.StatusUpdated(new object(), new EventArgs());
} 


public void Page_Load(object sender, EventArgs e)
{
    //.... 
}

protected void Button1_Click(object sender, EventArgs e)
{
    FunctionThatRaisesEvent();
}
}

and the designer for user control :

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SomeUserControl.ascx.cs" Inherits="SomeUserControl" %>
<asp:Button ID="Button1" runat="server" Text="Update" Height="70px" 
onclick="Button1_Click" Width="183px" />

and add this code for main page:

protected void Page_Load(object sender, EventArgs e)
{

}
protected void Unnamed1_Click(object sender, EventArgs e)
{
    SomeUserControl userControl = (SomeUserControl)LoadControl("SomeUserControl.ascx");
    userControl.StatusUpdated += new EventHandler(userControl_StatusUpdated);
    Panel1.Controls.Add(userControl);
}

void userControl_StatusUpdated(object sender, EventArgs e)
{
    GetDate();
}

private void GetDate()
{
    TextBox1.Text = DateTime.Today.ToString();
}

and designer for main page:

<%@ Register src="SomeUserControl.ascx" tagname="SomeUserControl" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="upd1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button runat="server" Text="Add User Control" Height="44px"  ID="Nims"
                onclick="Unnamed1_Click" Width="133px" />
                <asp:Panel ID="Panel1" runat="server" BackColor="#FFFFCC"></asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

    </form>
</body>
</html>

but it does not work and nothing happend. even I add break point for click user control button code but it seems that event not raise.

  • 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-06-06T15:19:11+00:00Added an answer on June 6, 2026 at 3:19 pm

    Raise the event from the user control, and handle the event from the main page. Check out this question.

    //** EDIT **//

    You are adding the user control dynamically on button click. When you click the button on your user control it first will initiate postback on the main page – now your user control no longer exists (which is why the event is not raised). If you change your main page designer to look like this:

    <%@ Register Src="SomeUserControl.ascx" tagname="SomeUserControl" tagprefix="uc1" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="upd1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button runat="server" Text="Add User Control" Height="44px"  ID="Nims"
                onclick="Unnamed1_Click" Width="133px" />
                <asp:Panel ID="Panel1" runat="server" BackColor="#FFFFCC">
                <uc1:SomeUserControl ID="userControl" runat="server" />
                </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    
    </form>
    

    and your code-behind to look like this

    protected void Page_Load(object sender, EventArgs e)
    {
        userControl.StatusUpdated += new EventHandler(userControl_StatusUpdated);
    }
    
    void userControl_StatusUpdated(object sender, EventArgs e)
    {
        GetDate();
    }
    
    private void GetDate()
    {
        TextBox1.Text = DateTime.Today.ToString();
    }
    

    you will see what I mean. Try setting breakpoints on the page load events of your main page and your user control to see exactly the order in which things happen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using vb.net code. I have grid view, please see the code below:
I have a grid view that has two simple columns, a report number and
i have a doubt in grid view. In Data list we have a property
I have grid something like this: Ext.define('Exp.view.dashboard.Tv', { extend: 'Ext.grid.Panel', initComponent: function() { this.columns
I have view page with both detailview and gridview the grid view should be
I have a ASP.Net web page with a grid view. I want to filter
I have used BaseAdapter for grid view, in getView method of BaseAdapter I am
I have a page that can be viewed by list or grid view through
I'm trying to load a page using $.ajax() . I have view person with
I have a main web page (Base Page) that makes an ajax call (using

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.