I would like to use contentpage controls from master page. the senario is like this...

I have project with master page and master page has a webusercontrol. webusercontrol has button. when webusercontrol button is clicked. the content page's text box should have a focus on it. Button is wrapped in updated panel as its ajax enabled site.

I googled the problem but not offered much help

thanks in anticipation!!!

Master Page

<%@ Master Language="VB" AutoEventWireup="false" Codebehind="MainMaster.master.vb"
    Inherits="Focus.MainMaster" %>
<%@ Register Src="WebUserControl1.ascx" TagName="WebUserControl1" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <form id="form1" runat="server">
     <asp:ScriptManager ID="ScriptManager1" runat="server">
        <uc1:WebUserControl1 ID="WebUserControl1_1" runat="server"></uc1:WebUserControl1>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <asp:Button ID="btnMasterPageButton" runat="server" Text="MasterPageButton" />
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

Master Page code behind

Public Partial Class MainMaster
    Inherits System.Web.UI.MasterPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Dim btnMain As Button = CType(ContentPlaceHolder1.FindControl("WebUserControl1").FindControl("btn_UC_Main_button"), Button)

    End Sub

    Protected Sub btnMasterPageButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMasterPageButton.Click
        Dim MyTxt As TextBox
        Dim strScript As String
        MyTxt = CType(ContentPlaceHolder1.FindControl("TextBox2"), TextBox)
        CType(ContentPlaceHolder1.FindControl("TextBox1"), TextBox).Text = MyTxt.Text
        CType(ContentPlaceHolder1.FindControl("TextBox1"), TextBox).Focus()

    End Sub
End Class

User Control

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="WebUserControl1.ascx.vb" Inherits="Focus.WebUserControl1" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <asp:Button ID="btn_UC_Main_button" runat="server" Text="UC_Main_button" />

User control code behind

Public Partial Class WebUserControl1
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Private Sub btn_UC_Main_button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_UC_Main_button.Click

        Dim MyTxt As TextBox
        MyTxt = CType(Page.Master.FindControl("ContentPlaceHolder1").FindControl("TextBox2"), TextBox)
        CType(Page.Master.FindControl("ContentPlaceHolder1").FindControl("TextBox1"), TextBox).Text = MyTxt.Text
        CType(Page.Master.FindControl("ScriptManager1"), ScriptManager).SetFocus(MyTxt.ClientID)
        ' ''Me.ScriptManager1.SetFocus(MyTxt.ClientID)
    End Sub
End Class

Web page .aspx

<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/MainMaster.Master" CodeBehind="WebForm1.aspx.vb" Inherits="Focus.WebForm1" 
    title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server" Text="Hello"></asp:TextBox>

WebPage code behind

Public Partial Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

End Class

Generally speaking, trying to access the content page from the master page is a pretty backwards way of doing something. If you have multiple content pages are they all going to implement this behavior? It would be easier, and make more sense, to put the user control into the content pages rather than putting the user control into the master page. This way you can include it only in the pages that would need it since most like not every content page would use it. Then you can access the content page through the "Page" property of the user control.

This question has already been answered. Start a new discussion instead.