Solved

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

Posted on 2010-09-03
6
641 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

785 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