Solved

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

Posted on 2010-09-03
6
635 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

12 Experts available now in Live!

Get 1:1 Help Now