Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Accessing Master Page control

Accessing Master Page control

Scheduled Pinned Locked Moved ASP.NET
helpcsharpquestionworkspace
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Syed Ferhat
    wrote on last edited by
    #1

    Hello Everyone I am new in .NET Environment. I m stuck with one problem Following is the thing which I need to do.. I have a Master Page in my application and I want to modify its control like LABEL text from content or on run time. following are the codes I am trying to use but its not working and given me error "NullReferenceException was Unhandeled by user Code" CODES Behind file of MasterPage : Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Label1.text="Naqvi" End Sub help me How do I fix this error

    P J S A 4 Replies Last reply
    0
    • S Syed Ferhat

      Hello Everyone I am new in .NET Environment. I m stuck with one problem Following is the thing which I need to do.. I have a Master Page in my application and I want to modify its control like LABEL text from content or on run time. following are the codes I am trying to use but its not working and given me error "NullReferenceException was Unhandeled by user Code" CODES Behind file of MasterPage : Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Label1.text="Naqvi" End Sub help me How do I fix this error

      P Offline
      P Offline
      prashant patil 4987
      wrote on last edited by
      #2

      :) :-D :laugh:

      S 1 Reply Last reply
      0
      • P prashant patil 4987

        :) :-D :laugh:

        S Offline
        S Offline
        Syed Ferhat
        wrote on last edited by
        #3

        Why laughing may I put some joke ?

        1 Reply Last reply
        0
        • S Syed Ferhat

          Hello Everyone I am new in .NET Environment. I m stuck with one problem Following is the thing which I need to do.. I have a Master Page in my application and I want to modify its control like LABEL text from content or on run time. following are the codes I am trying to use but its not working and given me error "NullReferenceException was Unhandeled by user Code" CODES Behind file of MasterPage : Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Label1.text="Naqvi" End Sub help me How do I fix this error

          J Offline
          J Offline
          jaideepsinh
          wrote on last edited by
          #4

          First of all tell us your project is in c#.net or vb.net and is it window application or webapplication. And NullReferenceException generate when you assign null value to which variable are not accept this value.

          S 1 Reply Last reply
          0
          • J jaideepsinh

            First of all tell us your project is in c#.net or vb.net and is it window application or webapplication. And NullReferenceException generate when you assign null value to which variable are not accept this value.

            S Offline
            S Offline
            Syed Ferhat
            wrote on last edited by
            #5

            Hi Jai I hope you don't mind as I wrote you Jai . Well Its VB.net Code and Its a Web Application. Thanks and hope for the best from you Regards Ferhat Naqvi

            1 Reply Last reply
            0
            • S Syed Ferhat

              Hello Everyone I am new in .NET Environment. I m stuck with one problem Following is the thing which I need to do.. I have a Master Page in my application and I want to modify its control like LABEL text from content or on run time. following are the codes I am trying to use but its not working and given me error "NullReferenceException was Unhandeled by user Code" CODES Behind file of MasterPage : Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Label1.text="Naqvi" End Sub help me How do I fix this error

              S Offline
              S Offline
              SKL_H
              wrote on last edited by
              #6

              Hi it is very simple you need to used the FindControl() method of your page, like ((Control)this.FindControl("Label1")).Text = "Naqvi";

              S 1 Reply Last reply
              0
              • S SKL_H

                Hi it is very simple you need to used the FindControl() method of your page, like ((Control)this.FindControl("Label1")).Text = "Naqvi";

                S Offline
                S Offline
                Syed Ferhat
                wrote on last edited by
                #7

                Hi Friend Thanks for your kind advice , I also tried to do the same by using FindControl method searching on the web but It's not working can you please show me the sample code

                1 Reply Last reply
                0
                • S Syed Ferhat

                  Hello Everyone I am new in .NET Environment. I m stuck with one problem Following is the thing which I need to do.. I have a Master Page in my application and I want to modify its control like LABEL text from content or on run time. following are the codes I am trying to use but its not working and given me error "NullReferenceException was Unhandeled by user Code" CODES Behind file of MasterPage : Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Label1.text="Naqvi" End Sub help me How do I fix this error

                  A Offline
                  A Offline
                  Aatif Ali from Bangalore
                  wrote on last edited by
                  #8

                  using System; using System.Web.UI.WebControls; Now add following code in code behind protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { Label masterlbl = (Label)Master.FindControl("lblMaster"); TextBox mastertxt = (TextBox) Master.FindControl("txtMaster"); lblContent.Text = masterlbl.Text; txtContent.Text = mastertxt.Text; } } Here 'txtMaster' is a textbox placed in the masterPage...u can try like this to get all controls from MasterPage

                  S 1 Reply Last reply
                  0
                  • A Aatif Ali from Bangalore

                    using System; using System.Web.UI.WebControls; Now add following code in code behind protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { Label masterlbl = (Label)Master.FindControl("lblMaster"); TextBox mastertxt = (TextBox) Master.FindControl("txtMaster"); lblContent.Text = masterlbl.Text; txtContent.Text = mastertxt.Text; } } Here 'txtMaster' is a textbox placed in the masterPage...u can try like this to get all controls from MasterPage

                    S Offline
                    S Offline
                    Syed Ferhat
                    wrote on last edited by
                    #9

                    Salam & Good Day Aatif Many thanks for your support. But actually you can give me the C# code and I am using VB.NET following are the codes. DirectCast(SelectSurvey.FindControl("lblMaster"), DropDownList) But It give error on "SelectSurvey.FindControl" where SelectSurvey is page where that control exist. Infect there is no .FindControl property in list when I give the page name and pressing DOT(.) can you I also add two reference of class as below Imports System Imports System.Web.UI.WebControls Can you please let me know why. Your quick reply will be highly appreciated Regards Ferhat

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups