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"> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <uc1:WebUserControl1 ID="WebUserControl1_1" runat="server"></uc1:WebUserControl1> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="btnMasterPageButton" runat="server" Text="MasterPageButton" /> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html>
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() Me.ScriptManager1.SetFocus(MyTxt.ClientID) Page.SetFocus(MyTxt.ClientID) '_setFocus(MyTxt.ClientID) End Sub End Class
User Control
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="WebUserControl1.ascx.vb" Inherits="Focus.WebUserControl1" %> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="btn_UC_Main_button" runat="server" Text="UC_Main_button" /> </ContentTemplate> </asp:UpdatePanel>
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 'WANT TO WRITE CODE HERE ON CLICK SET FOCUS ON CONTENT'S (WEBFORM1.ASPX) PAGE TEXTBOX 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> </asp:Content>
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
Hi,
I have an application in ASP.net coding is in C#.net, where in the master page is a part of content page, and i require to access few hidden variables put up on my content page from the master page.
Can any one suggest how can i do this..
Thanks in advance..
Shabana B