Need help with User Control in ASP.NET using C#...

Posted on 2009-05-15
Last Modified: 2013-11-05

I have a master page (MainPage.master) that uses a custom user control (MyUserControl.ascx). On load of MainPage.master, I get an error saying the "GoNext" method / function (from the OnClick event of the ImageButton) cannot be found.  How can I solve this?  Does this have anything to do with having to expose certain methods / properties?

Thank you very much in advance.

        <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyUserControl.ascx.cs" Inherits="UserControls_MyUserControl" %>

        <table width="950px" border="0">


                <td rowspan="2" width="163px" align="left">

                    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

			 My content 1



                <td width="547px" align="right" valign="bottom">

                    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">

			 My content 2



                <td width="30px">&nbsp;</td>

                <td width="210px" align="right" valign="middle">

                    <asp:Panel runat="server" ID="Panel1" DefaultButton="btnGo">

                        <asp:TextBox ID="txtProduct" runat="server"></asp:TextBox>

                        <asp:ImageButton runat="server" ID="btnGo" OnClick="GoNext" CommandArgument="S" ImageUrl="images/btn_go.gif" AlternateText="Go"></asp:ImageButton>





                <td width="547px">&nbsp;</td>

                <td width="30px">&nbsp;</td>

                <td width="210px" align="right" valign="top">

                    <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">

			 My content 3





Master Page (MainPage.master) that uses MyUserControl.ascx:

<%@ Master Language="C#" EnableViewState="true" AutoEventWireup="true" CodeFile="MainPage.master.cs" Inherits="MainPage" %>

<%@ Register src="UserControls/MyUserControl.ascx" tagname="ProductControl" tagprefix="user" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">

    <title>Untitled Page</title>



	<user:ProductControl ID="UserControl1" runat="server" />

        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">            


        <asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server">            


        <asp:ContentPlaceHolder id="ContentPlaceHolder3" runat="server">            





public partial class MainPage : System.Web.UI.MasterPage


    protected void Page_Load(object sender, EventArgs e)



    protected void GoNext(object sender, EventArgs e)


        ImageButton button = (ImageButton)sender;

        string arg = button.CommandArgument;

        switch (arg)


            case "S":

                if (txtSearch.Text != "")






            case "T":




            default: break;




Open in new window

Question by:WebAppDeveloper
LVL 12

Accepted Solution

needo_jee earned 500 total points
ID: 24399864

the method GoNext should be located in Usercontrol's cs (MyUserControl.ascx.cs) but seems you have put in Master page ' code file?


Author Comment

ID: 24399886

Yes, I've put it in the master page's code behind file. Ok, I'll try to move it to Usercontrol.cs, and see how it goes. It makes sense now.


Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now