Solved

Calling method in Usercontrol

Posted on 2007-11-16
5
1,726 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
  • 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with sorting data in Listbox using VB.NET 3 53
DataGridView Events ? 3 37
Host asp.net pages 5 25
SQL Exceptions 3 36
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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

20 Experts available now in Live!

Get 1:1 Help Now