Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-05-15
2
Medium Priority
?
183 Views
Last Modified: 2013-11-05
Hi,

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.
MyUserControl.ascx:
        <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyUserControl.ascx.cs" Inherits="UserControls_MyUserControl" %>
 
        <table width="950px" border="0">
            <tr>
                <td rowspan="2" width="163px" align="left">
                    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
			 My content 1
		    </asp:Content>
                </td>
                <td width="547px" align="right" valign="bottom">
                    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
			 My content 2
		    </asp:Content>
                </td>
                <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>
                    </asp:Panel>
                </td>
            </tr>
            <tr>
                <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
		    </asp:Content>
                </td>
            </tr>
        </table>
 
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
	<user:ProductControl ID="UserControl1" runat="server" />
 
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">            
        </asp:ContentPlaceHolder>
 
        <asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server">            
        </asp:ContentPlaceHolder>
 
        <asp:ContentPlaceHolder id="ContentPlaceHolder3" runat="server">            
        </asp:ContentPlaceHolder>
 
</body>
</html>
 
MainPage.master.cs:
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 != "")
                {
                    Response.Redirect("~/VMSP_Search.aspx?search="+txtSearch.Text);
                }
                break;
            /**
            case "T":
                Response.Redirect("http://www.somewhere.com");
                break;
            **/
            default: break;
        }
    }
}

Open in new window

0
Comment
Question by:WebAppDeveloper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
Munawar Hussain earned 2000 total points
ID: 24399864
hi,

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

-thanks
0
 

Author Comment

by:WebAppDeveloper
ID: 24399886
needo_jee,

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.

Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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