Solved

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

Posted on 2010-09-03
6
637 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

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 …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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