Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I Update a Master Page Control from Web User Control

Posted on 2010-09-03
6
Medium Priority
?
650 Views
Last Modified: 2012-05-10
Using
ASP.NET
C#
VS2008

Here is my page structure

MasterPage.Master
    NestedMasterPage.Master
            (SQLDataSourceControl)
        WebContentForm.aspx
            WebUserControl.ascx
                Button
                    ButtonClickMethod
                        {Rebind the SQLDataSource control on the NestedMasterPage.Master}
                Button
            WebUserControl.ascx
        WebContentForm.aspx
    NestedMasterPage.Master
MasterPage.Master

Using the page structure above I need to access and rebind an SQLDataSource Control on the NestedMaster.Master (or any other control for that matter) from the WebUserControl

Can anybody help

Thanks very much
Puds32
0
Comment
Question by:Puds32
[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
6 Comments
 
LVL 12

Expert Comment

by:w00te
ID: 33598449
Use find control on the masterpage through the page using the masterpage.  Here's a good detailed example:
http://www.west-wind.com/Weblog/posts/5127.aspx 
I think it should work with datasource even though its not a visible control.
-w00te
0
 
LVL 3

Expert Comment

by:JessyEzzy
ID: 33601134
I've attached an example in which there a TextBox control in the Nested Master Page and there's a TextBox control and a Button in the WebUserControl which is in the WebContentForm. When clicking the button the value of the TextBox in the user control is copied into the TextBox in the Nested Master Page.
You can replace the code with your code that rebinds the SqlDataSource.

The idea is in the WebContentForm you have to include this directive:
<%@ MasterType VirtualPath="~/NestedMasterPage.master" %>
to be able to call methods defined on the master page from within the web page through the "Master" property, then using a delegate so that the user control can communicate with its parent page and call the method defined in the parent page that will call the method defined in the nested master page.

HTH
Example.zip
0
 

Author Comment

by:Puds32
ID: 33616347
Thanks so much for your time and effort, I will be trying it out later today and will give an update then

Puds32
0
Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

 

Author Comment

by:Puds32
ID: 33647582
Hi JessyEzzy

I have set up a project and run your example, does run and does what it says on the tin but I amd getting the following errors, are you able to help me out with them?, The errors are:

Error      1      The name 'WebUserControl1' does not exist in the current context      C:\FindControl\WebContentForm.aspx.cs      12      9      FindControl

Error      2      The name 'TextBox1' does not exist in the current context      C:\FindControl\NestedMasterPage.master.cs      17      9      FindControl

Error      3      'System.Web.UI.MasterPage' does not contain a definition for 'updateTextBox' and no extension method 'updateTextBox' accepting a first argument of type 'System.Web.UI.MasterPage' could be found (are you missing a using directive or an assembly reference?)      C:\FindControl\WebContentForm.aspx.cs      17      16      FindControl

Error      4      The name 'TextBox1' does not exist in the current context      C:\FindControl\WebUserControl.ascx.cs      22      26      FindControl


Thanks Puds32
0
 
LVL 3

Accepted Solution

by:
JessyEzzy earned 2000 total points
ID: 33690466
Hi Puds32,
I would really like to help you but I don't understand how come you're getting those errors while you said it does run and does what it says on the tin?
If you're getting these errors then nothing is running, did you place the 8 files all together in the website folder? The example contains these files:
1)MasterPage.master
2)MasterPager.master.cs
3)NestedMasterPage.master
4)NesterMasterPage.master.cs
5)WebContentForm.aspx
6)WebContentForm.aspx.cs
7)WebUserControl.ascx
8)WebUserControl.ascx.cs
0
 

Author Closing Comment

by:Puds32
ID: 33867379
Hi JessyEzzy
Sorry for delay hade a few problems getting back into the question!!!
I figured out where I went wrong - had one of the partial classes wrong - Doh
Your solution worked briliantly thanks very much.

Puds32
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

715 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