Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling method in Usercontrol

Posted on 2007-11-16
5
Medium Priority
?
1,734 Views
Last Modified: 2013-11-07
Hi,

I am working on C#, Asp.net 2.0
I have a user control with id WucMainPage1 and inside this control there is another control used with id WucPages1

I want to call a method fillPageType(); which is inside usercontrol WucPages1

How should I do it.

Please guide.

I am trying with various method:

      UserControl WucPages1 = (UserControl)WucMainPage1.FindControl("WucPages1");
//      Type myType = typeof(WucPages1);
//      MethodInfo myMethodInfo = myType.GetMethod("fillPageType");
//      myType.InvokeMember(function,BindingFlags.InvokeMethod, null, null, null);

      //WucPages1.LoadControl

      // WucPages1.fillPageType();
      //  WucPages1.BindPageGrid();
      
      
Thanks,
0
Comment
Question by:tia_kamakshi
[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
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Thejaka
ID: 20300010
Assuming your UserControl is named "WucPages"...

WucPages WucPages1 = (WucPages)WucMainPage1.FindControl("WucPages1");
WucPages1.fillPageType();

Open in new window

0
 

Author Comment

by:tia_kamakshi
ID: 20300362
Error Says:

Error      1      
The type or namespace name 'WucPages' could not be found (are you missing a using directive or an assembly reference?)


I have control where wucMainPage.ascx is registered. Inside wucMainPage.ascx control wucPages.ascx is registered.

Now in Page wucPages.ascx, I have method fillPageType(), which I wish to access from wucCourseContent.ascx.cs

Thanks


-- wucCourseContent.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="wucCourseContent.ascx.cs" Inherits="VW_Controls_wucCourseContent" %>
<%@ Register Src="wucMainPage.ascx" TagName="wucMainPage" TagPrefix="uc1" %>
<%@ Register Src="wucMainModule.ascx" TagName="wucMainModule" TagPrefix="uc2" %>
<%@ Register Src="wucMainCourse.ascx" TagName="wucMainCourse" TagPrefix="uc3" %>

<div class="LnkBtndiv"><asp:LinkButton ID="btnPage" runat="server" Text="Page" OnClick ="btnPage_Click" /></div>
<div class="LnkBtndiv"><asp:LinkButton ID="btnModule" runat="server" Text="Module" OnClick ="btnModule_Click"/></div>
<div class="LnkBtndiv"><asp:LinkButton ID="btnCourse" runat="server" Text="Course" OnClick ="btnCourse_Click"/></div>

<br clear="all" />

<asp:HiddenField runat="server" ID="hdnTabClick" Value="0" />

      <asp:MultiView runat="server" ID="mvCourseContent" ActiveViewIndex="0" OnActiveViewChanged="mvCourseContent_ActiveViewChanged" >
                <asp:View ID="vwPages" runat="server">
                    <uc1:wucMainPage ID="WucMainPage1" runat="server" />
                </asp:View>
                <asp:View ID="vwModule" runat="server">
                    <uc2:wucMainModule ID="WucMainModule1" runat="server" />
                </asp:View>                
                <asp:View ID="vwCourse" runat="server">
                    <uc3:wucMainCourse ID="WucMainCourse1" runat="server" />
                </asp:View>
               
    </asp:MultiView>
   
   
   
    -- wucMainPage.ascx


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="wucMainPage.ascx.cs" Inherits="VW_Controls_wucMainPage" %>
<%@ Register Src="wucUploadImages.ascx" TagName="wucUploadImages" TagPrefix="uc1" %>
<%@ Register Src="wucPages.ascx" TagName="wucPages" TagPrefix="uc3" %>
<%@ Register Src="wucQuestions.ascx" TagName="wucQuestions" TagPrefix="uc5" %>
<%@ Register Src="wucGlossary.ascx"  TagName="wucGlossary" TagPrefix="uc6" %>
<div class="LnkBtndiv1"><asp:LinkButton ID="btnPage" runat="server" Text="Page" OnClick="btnPage_Click" /></div>
<div class="LnkBtndiv1"><asp:LinkButton ID="btnQuestion" runat="server" Text="Question" OnClick="btnQuestion_Click" /></div>
<div class="LnkBtndiv1"><asp:LinkButton ID="btnGlossary" runat="server" Text="Glossary" OnClick="btnGlossary_Click" /></div>
<div class="LnkBtndiv1"><asp:LinkButton ID="btnImages" runat="server" Text="Upload Images" OnClick="btnImages_Click" /></div>
<asp:HiddenField runat="server" ID="hdnTabClick" Value="1" />

<br clear="all" />
<asp:MultiView runat="server" ID="mvCourseManagement" ActiveViewIndex="0" OnActiveViewChanged="mvCourseManagement_ActiveViewChanged" >
      <asp:View ID="vwPages" runat="server">
            <uc3:wucPages ID="WucPages1" runat="server" />
      </asp:View>
      <asp:View ID="vwQuestion" runat="server">
            <uc5:wucQuestions ID="WucQuestions1" runat="server" />
      </asp:View>
      <asp:View ID="vwGlossary" runat="server">
            <uc6:wucGlossary ID="WucGlossary1" runat="server" />
      </asp:View>
    <asp:View ID="vwImages" runat="server">
        <uc1:wucUploadImages ID="WucUploadImages1" runat="server" />
            
      </asp:View>
</asp:MultiView>



Now Inside control file wucPages.ascx, I have a method


public void fillPageType()
{
      oTypeMstrBL = new TypeMstrBL();
      int iApplyLevel = 3;

      DataTable odt = oTypeMstrBL.GetCategoryListing(iApplyLevel);

      ddlPageType.DataSource = odt;
      ddlPageType.DataBind();

      ddlPageType.Items.Insert(0, new ListItem("-- Select Type --", ""));
}
0
 
LVL 8

Expert Comment

by:Thejaka
ID: 20301552
In this case you'll have to declare a public property or method to expose the method in the inner control to the outer one.

You should also add the following reference:

-- wucCourseContent.ascx

<%@ Reference Control="wucPages.ascx"%>


/*** wucMainPage.ascx.cs ***/
 
public property ASP_WucPages WucPages1_1
{
  get { return WucPages1; }
}
 
 
/*** wucCourseContent.ascx.cs ***/
 
WucMainPage1.WucPages1_1.fillPageType();

Open in new window

0
 
LVL 8

Accepted Solution

by:
Thejaka earned 2000 total points
ID: 20301584
The other option is to simply expose a method:
/*** wucMainPage.ascx.cs ***/
 
public void WucPages1_fillPageType()
{
  WucPages1.fillPageType();
}
 
 
/*** wucCourseContent.ascx.cs ***/
 
WucMainPage1.WucPages1_fillPageType();

Open in new window

0
 

Author Closing Comment

by:tia_kamakshi
ID: 31409593
Cool and Many Thanks :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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