Wednesday, 10 May 2017

Get Master Page Control Value On content page

Hello To All
I have a Master Page Like

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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">
<head runat="server">
  <title></title>
  <asp:ContentPlaceHolder ID="head" runat="server">
  </asp:ContentPlaceHolder>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <asp:Label ID="Label1" runat="server" Text="Kshama"></asp:Label>
    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
    </asp:ContentPlaceHolder>
  </div>
  </form>
</body>
</html>
And content page Like

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
  CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
  <telerik:RadGrid ID="RadGrid1" runat="server">
  </telerik:RadGrid>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server">
    <InsertParameters>
      <asp:Parameter Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32" />
      <asp:Parameter Name="classname" Type="String" />
      <asp:Parameter Name="section" Type="String" />
    </InsertParameters>
  </asp:SqlDataSource>
</asp:Content>
Now Problem is that I need Master Page Label1 Text In

<asp:ControlParameter ControlID="Label1" Name="Branch_code" PropertyName="Text" />
in InsertParameter How Can I get Label1 Text in sqldatasource insertparameters......

Reply

shree_ars
Member
Jul 20, 2012 03:39 AM

yes..u can..

try putting script manager in ur master page.. and in the content page

from the scriptmanger u can able to retrive the control object and get the values of what ever control u need it.

If you win, you need not have to explain...If you lose, you should not be there to explain!
Reply

kshama
Member
Jul 20, 2012 03:41 AM

How Can I do this

any example.

Reply

shree_ars
Member
Re: Get Master Page Control Value On content page
Jul 20, 2012 06:42 AM

string str = ((TextBox)ScriptManager.GetCurrent(this).FindControl("textBox1")).Text;

in the above code..."textBox1" is placed in maser page.

and the above code u just place in ur content page and check it.

If you win, you need not have to explain...If you lose, you should not be there to explain!
Reply

Damn Code
Participant
Re: Get Master Page Control Value On content page
Jul 21, 2012 06:21 PM

Hi, friend

if you wanna get control value from master page

use to write this on content page

string str = ((Label)Master.FindControl("Label1")).Text;
Reply

Frank Jiang...
All-Star
Re: Get Master Page Control Value On content page
Jul 25, 2012 03:47 AM

kshama
Now Problem is that I need Master Page Label1 Text In

<asp:ControlParameter ControlID="Label1" Name="Branch_code" PropertyName="Text" />
in InsertParameter How Can I get Label1 Text in sqldatasource insertparameters......

  protected void insert_OnCLick(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        Label lblMaster = (Label)this.Master.FindControl("LabelID");
        if (lblMaster != null)
        {
            SqlDataSource1.InsertParameters("classname").DefaultValue = lblMaster.Text;
        }   
        SqlDataSource1.Insert();
    }

No comments:

Post a Comment