?
Solved

Access of parent page of a user control doesn't work

Posted on 2009-12-22
4
Medium Priority
?
375 Views
Last Modified: 2012-06-27
I have written a user control that is in a AJAX Tab Panel of the main page. When a button in teh user control is clicked the next page of the Tab Container will be called. In the ButtonThey way I understood the necassary cast doesn't work. I get an error "OrdersDE_PlaceOrder is not defined". What is the problem?
------------------------------------
UserControl ucCompPackages.ascx.vb
------------------------------------

Imports dbRTSFLib
Imports RTSFPricesLib

Partial Public Class ucCompPackages
    Inherits System.Web.UI.UserControl

   ...
    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Dim pPage As Page = Me.Page
        Dim tcCompPackages As AjaxControlToolkit.TabContainer = CType(Me.Page, OrdersDE_PlaceOrder).tabPlaceOrder

    End Sub
End Class

----------------------------------
User Control usCompPackages.ascx
----------------------------------

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ucCompPackages.ascx.vb" Inherits="ucCompPackages" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<link href="../CSS/RTSOrders.css" rel="stylesheet" type="text/css" />
<div>
...
</div>

------------------------------
Main Page PlaceOrder.aspx
------------------------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="PlaceOrder.aspx.vb" Inherits="OrdersDE_PlaceOrder" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register TagPrefix="uc" TagName="CompPackages" Src="~/controls/ucCompPackages.ascx" %>

<!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">
...
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">        </asp:ToolkitScriptManager>                
  <div id="divTabContainer">
  <asp:TabContainer ID="tabPlaceOrder" runat="server" ActiveTabIndex="3">
      <asp:TabPanel runat="server" HeaderText="<%$ Resources:Text, TabPackages %>" ID="tabPackages">
  <ContentTemplate>
       <uc:CompPackages id="ucComplPacks" runat="server" />
   </ContentTemplate>
    </asp:TabPanel>
...

----------------------------
Main Page PlaceOrder.aspx
----------------------------

Imports System.Globalization
Imports System.Threading
Imports dbRTSFLib
Imports RTSFPricesLib

Partial Class OrdersDE_PlaceOrder
    Inherits System.Web.UI.Page
...
End Class

Open in new window

0
Comment
Question by:MarcusKoch
  • 2
3 Comments
 
LVL 3

Expert Comment

by:ianmair329
ID: 26109269
you could try using FindControl
or the following...
http://lekshmi.org/2008/11/27/find-parent-controlid-from-a-child-control/

you cant address you "OrdersDE_PlaceOrder" class from within the control as you havent instantiated it, but then you wouldnt want to in this case.
let me know if the URL helps, standing by to assist
0
 
LVL 3

Accepted Solution

by:
ianmair329 earned 1000 total points
ID: 26109284
In your UserControl ucCompPackages.ascx.vb try the following...
'Instead of 
Dim tcCompPackages As AjaxControlToolkit.TabContainer = CType(Me.Page, OrdersDE_PlaceOrder).tabPlaceOrder

'Try using
Dim tcCompPackages As AjaxControlToolkit.TabContainer = CType(Me.Page.FindControlRecursively("tabPlaceOrder"), AjaxControlToolkit.TabContainer)

Open in new window

0
 

Author Comment

by:MarcusKoch
ID: 26110646
Thanks for the FindControl tip. I'm aware of it and will try it. The other solution with a cast to the page class should work. I have seen it in many examples and it is the direct way, but I don't understand why it doesn't work in my case.

Marcus
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 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