Accessing Master Page control
-
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
-
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
:) :-D :laugh:
-
:) :-D :laugh:
Why laughing may I put some joke ?
-
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
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.
-
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.
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
-
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
-
Hi it is very simple you need to used the FindControl() method of your page, like ((Control)this.FindControl("Label1")).Text = "Naqvi";
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
-
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
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
-
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
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