Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-03
6
Medium Priority
?
658 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
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…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

773 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