Solved

Calling method in Usercontrol

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

18 Experts available now in Live!

Get 1:1 Help Now