Solved

Calling method in Usercontrol

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 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