• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1262
  • Last Modified:

How to update/reference label1.text nested in an ajax tab container from behind code

I can't update my  ProfileNameLabel.Text because I do not know how to reference in from the ajax control tab container.  

<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
                <ajaxToolkit:TabPanel ID="Info" runat="server" HeaderText="Info" TabIndex="0">
                    <ContentTemplate>
                        <asp:HyperLink ID="ProfilePic" runat="server" NavigateUrl="~/Profile/DisplayPicture.aspx?UserID={0}" ToolTip="Profile Pic Home">
                        <asp:Image ID="Image1" runat="server" ImageUrl="~/Profile/DisplayThumb.aspx?UserID={0}" AlternateText="ProfilePic" />
                        </asp:HyperLink>  
                        <br />
                        <asp:Label ID="ProfileNameLabel" runat="server" />
                        <br />        
                        <asp:Label ID="SkateStanceLabel" runat="server" />
                        <br />
                        <asp:Label ID="FavTricksLabel" runat="server" />
                        <br />
                        <asp:Label ID="FavSpotsLabel"  runat="server"/>
                        <br />
                        <asp:Label ID="FavSkatersLabel"  runat="server"/>
                        <br />
                        <asp:Label ID="FavVideopartsLabel"  runat="server"/>
                        <br />
                        <asp:Label ID="FavSongsLabel"  runat="server"/>
                        <br />
                        <asp:Label ID="LocationLabel"  runat="server"/>
                        <br />
                        <asp:Label ID="AboutMeLabel"  runat="server"/>
                        <br />
                    </ContentTemplate>
                </ajaxToolkit:TabPanel>
             
            </ajaxToolkit:TabContainer>
Using myCommand As New SqlCommand("AGProfileSelect", myConnection)
     myCommand.CommandType = CommandType.StoredProcedure
      myConnection.Open()
      myCommand.Parameters.AddWithValue("@UserId", CurrentUser)
           Dim dr As SqlDataReader = myCommand.ExecuteReader()
             dr.Read()
              ProfileNameLabel.Text = dr("ProfileName").ToString().Trim()
 
             dr.Close()
      myConnection.Close()
 
End Using
End Using

Open in new window

0
HarleySkater
Asked:
HarleySkater
  • 11
  • 6
1 Solution
 
Anurag ThakurTechnical ManagerCommented:
you should be able to as far as i can see by looking at your code

but you can try a little modification
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
      <ajaxToolkit:TabPanel ID="Info" runat="server" HeaderText="Info" TabIndex="0">
            <asp:UpdatePanel ID="upMemberInfoDetails" runat="server">
                  <ContentTemplate>
                  </ContentTemplate>
            </asp:UpdatePanel>
            </ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
0
 
HarleySkaterAuthor Commented:
it doesn't see it I think, because it has to reference the ajax tab container and then the label
0
 
Anurag ThakurTechnical ManagerCommented:
i am using the above defined code snippet where i have my controls on the update panel and i am able to use them without any special methods
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
HarleySkaterAuthor Commented:
hmmmmmmm I get this error

Error      1      Type 'AjaxControlToolkit.TabPanel' does not have a public property named 'UpdatePanel'.            
0
 
HarleySkaterAuthor Commented:
i am using asp.net 3.5 also :P
0
 
HarleySkaterAuthor Commented:
I never really posted my error - so I will do that now

system.nullreference.expection {"Object reference not set to an instance of an object."}  sorry :D
0
 
Anurag ThakurTechnical ManagerCommented:
UpdatePanel is not part of ajaxtool kit or comes by default
for that you will need to download and install it http://www.asp.net/AJAX/downloads/

how to use http://www.asp.net/ajax/
0
 
HarleySkaterAuthor Commented:
Hi Ragi0017 good morning :D

remember, I am using a ajax tab container :D  also I am using visual studio 2008 and asp.net 3.5.  My ajax is installed an working properly.  

The reason why your code didn't work for me is I wasn't paying close enough attention:

<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
      <ajaxToolkit:TabPanel ID="Info" runat="server" HeaderText="Info" TabIndex="0">
            <asp:UpdatePanel ID="upMemberInfoDetails" runat="server">
                  <ContentTemplate>
                  </ContentTemplate>
            </asp:UpdatePanel>
            </ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>

Placing the updatepanel outside of the content template why I had the error.  html and asp code has to be placed inside of the content template.  but after I did the switcharoo and placed the updatepanel in the correct place, I placed my labels inside the updatepanel of course and ran it with my labels commented out.  worked perfectly, but showed nothing in that tab container, I left my other tab containers alone.  Then I took the commenting off the labels in my behind code.  then I get this error



system.nullreference.expection {"Object reference not set to an instance of an object."}  sorry :D

I researched that and came up with a lot of stuff.  But I think this defines it well
""In Asp.Net this error is so common.

When you are trying to access a member of a class without instance object you will get Object reference not set to an instance of an object error.

So ensure that you are accessing the members with the instance of the class.

Example:

Cause of error:

public class ABC{
public void function xyz{....}
}

public class DEF{
ABC obj1;
obj1.xyz();
}

The highlighted line indicates that you have declared a variable of type ABC, but not the object reference or you just have created Object instance.

We can call methods or member variables only if we get reference to the instance of a object.

More technically,
ABC obj1; will not create any reference in memory.""

I have this event in my page_load sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

is this an order of operations problem??? I think page load is initializing the behind code before the ajax tab container and its allowing me to reference the objects on the tab container, but trying to access them before they are intialized?  

I know its not my code, because I snagged the code of a regular aspx page that I was already using elsewhere.  Its the code mixed with this ajax tab container

Thanks for your help so far!   :D I still need it though, because I am still stuck :D hehehe

0
 
Anurag ThakurTechnical ManagerCommented:
can you please share your code so that i can try that at my end and try to find out where the things are going wrong
0
 
HarleySkaterAuthor Commented:
<%@ Page Title="Anti-Gravity | Settings" Language="VB" MasterPageFile="~/AGMaster.master" AutoEventWireup="false" CodeFile="Settings.aspx.vb" Inherits="Settings" %>


<asp:Content ID="Content1" ContentPlaceHolderID="AgMainContent" Runat="Server">
<br />
<br />
    <asp:LoginView ID="LoginView1" runat="server">
    <LoggedInTemplate>
                <br />
            Login User: <asp:LoginName ID="LoginName1" runat="server" />
                <br />
               
               
            <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
                <ajaxToolkit:TabPanel ID="Info" runat="server" HeaderText="Info" TabIndex="0">
                    <ContentTemplate>
                        <asp:HyperLink ID="ProfilePic" runat="server" NavigateUrl="~/Profile/DisplayPicture.aspx?UserID={0}" ToolTip="Profile Pic Home">
                        <asp:Image ID="Image1" runat="server" ImageUrl="~/Profile/DisplayThumb.aspx?UserID={0}" AlternateText="ProfilePic" />
                        </asp:HyperLink>  
                        <br />
                        <asp:Label ID="ProfileNameLabel" runat="server" />
                        <br />        
                        <asp:Label ID="SkateStanceLabel" runat="server" />
                        <br />
                        <asp:Label ID="FavTricksLabel" runat="server" />
                        <br />
                        <asp:Label ID="FavSpotsLabel"  runat="server"/>
                        <br />
                        <asp:Label ID="FavSkatersLabel"  runat="server"/>
                        <br />
                        <asp:Label ID="FavVideopartsLabel"  runat="server"/>
                        <br />
                        <asp:Label ID="FavSongsLabel"  runat="server"/>
                        <br />
                        <asp:Label ID="LocationLabel"  runat="server"/>
                        <br />
                        <asp:Label ID="AboutMeLabel"  runat="server"/>
                        <br />
                    </ContentTemplate>
                </ajaxToolkit:TabPanel>
                <ajaxToolkit:TabPanel ID="Themes" runat="server" HeaderText="Themes" TabIndex="1">
                    <ContentTemplate>
                            <br />
                            Choose a Theme:
                            <asp:DropDownList ID="DropDownList1" runat="server">
                                <asp:ListItem>Space</asp:ListItem>
                                <asp:ListItem>Rusted</asp:ListItem>                                
                            </asp:DropDownList>
                            <br />
                            <br />
                            <asp:Button ID="SaveSettingsBttn" runat="server" Text="Save Settings" />
                                <br />
                                <br />
                    </ContentTemplate>
                </ajaxToolkit:TabPanel>
                <ajaxToolkit:TabPanel ID="Password" runat="server" HeaderText="Password" TabIndex="2">
                    <ContentTemplate>
                            <asp:ChangePassword ID="ChangePassword1" runat="server">
                            </asp:ChangePassword>    
                    </ContentTemplate>

                </ajaxToolkit:TabPanel>
             
            </ajaxToolkit:TabContainer>
           
           




    </LoggedInTemplate>
        <AnonymousTemplate>
            <asp:HyperLink ID="AGSettingsSignupPageLink" runat="server" NavigateUrl="~/Signup/Signup.aspx" ToolTip="Signup" style="color: #FF3300">
                New User Signup
            </asp:HyperLink>
        </AnonymousTemplate>
    </asp:LoginView>

    <p>



    </p>
</asp:Content>
Imports System.Data.SqlClient
Imports System.Data
 
Partial Class Settings
    Inherits System.Web.UI.Page
 
    Protected Sub Page_PagePrePreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Page.Theme = Profile.MyTheme
 
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' DropDownList1.Items.FindByValue(Profile.MyTheme)
        Dim CurrentUser As String = Nothing
 
        If User.Identity.IsAuthenticated Then
 
            CurrentUser = Membership.GetUser().ProviderUserKey.ToString()
            Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("AGConnectionString").ConnectionString)
 
                Using myCommand As New SqlCommand("AGProfileSelect", myConnection)
 
 
                    myCommand.CommandType = CommandType.StoredProcedure
                    myConnection.Open()
 
                    myCommand.Parameters.AddWithValue("@UserId", CurrentUser)
 
                    Dim dr As SqlDataReader = myCommand.ExecuteReader()
                    dr.Read()
 
                    'ProfileNameLabel.Text = dr("ProfileName").ToString().Trim()
                    'SkateStanceLabel.Text = dr("SkateStance").ToString().Trim()
                    'FavTricksLabel.Text = dr("FavTricks").ToString().Trim()
                    'FavSpotsLabel.Text = dr("FavSpots").ToString().Trim()
                    'FavSkatersLabel.Text = dr("FavSkaters").ToString().Trim()
                    'FavVideopartsLabel.Text = dr("FavVideoparts").ToString().Trim()
                    'FavSongsLabel.Text = dr("FavSongs").ToString().Trim()
                    'LocationLabel.Text = dr("Location").ToString().Trim()
                    'AboutMeLabel.Text = dr("AboutMe").ToString().Trim()
                    dr.Close()
                    myConnection.Close()
 
                End Using
            End Using
 
        Else
            Server.Transfer("~/default.aspx")
            Exit Sub
        End If
 
    End Sub
 
    Protected Sub SaveSettingsBttn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveSettingsBttn.Click
        Profile.FullName = Page.User.Identity.Name.ToString()
        Profile.MyTheme = DropDownList1.SelectedValue
 
        Response.Redirect("~/Default.aspx")
    End Sub
 
End Class

Open in new window

0
 
Anurag ThakurTechnical ManagerCommented:
i ran your code and i was able to access the ProfileNameLabel.Text as required
below is my code (slightly modified from what you are using)
but nearly the same


	<form id="form1" runat="server">
		<AjaxControlToolkit:ToolkitScriptManager ID="test" runat="server" AsyncPostBackTimeout="900" EnablePartialRendering="true">
		</AjaxControlToolkit:ToolkitScriptManager>
		<AjaxControlToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
			<AjaxControlToolkit:TabPanel ID="Info" runat="server" HeaderText="Info" TabIndex="0">
				<ContentTemplate>
					<asp:HyperLink ID="ProfilePic" runat="server" ToolTip="Profile Pic Home">
						<asp:Image ID="Image1" runat="server" AlternateText="ProfilePic" />
					</asp:HyperLink>
					<br />
					<asp:Label ID="ProfileNameLabel" runat="server"></asp:Label>
					<br />
					<asp:Label ID="SkateStanceLabel" runat="server"></asp:Label>
					<br />
					<asp:Label ID="FavTricksLabel" runat="server"></asp:Label>
					<br />
					<asp:Label ID="FavSpotsLabel" runat="server"></asp:Label>
					<br />
					<asp:Label ID="FavSkatersLabel" runat="server"></asp:Label>
					<br />
					<asp:Label ID="FavVideopartsLabel" runat="server"></asp:Label>
					<br />
					<asp:Label ID="FavSongsLabel" runat="server"></asp:Label>
					<br />
					<asp:Label ID="LocationLabel" runat="server"></asp:Label>
					<br />
					<asp:Label ID="AboutMeLabel" runat="server"></asp:Label>
					<br />
				</ContentTemplate>
			</AjaxControlToolkit:TabPanel>
			<AjaxControlToolkit:TabPanel ID="Themes" runat="server" HeaderText="Themes" TabIndex="1">
				<ContentTemplate>
					<br />
					Choose a Theme:
					<asp:DropDownList ID="DropDownList1" runat="server">
						<asp:ListItem>Space</asp:ListItem>
						<asp:ListItem>Rusted</asp:ListItem>
					</asp:DropDownList>
					<br />
					<br />
					<asp:Button ID="SaveSettingsBttn" runat="server" Text="Save Settings" />
					<br />
					<br />
				</ContentTemplate>
			</AjaxControlToolkit:TabPanel>
			<AjaxControlToolkit:TabPanel ID="Password" runat="server" HeaderText="Password" TabIndex="2">
				<ContentTemplate>
					<asp:ChangePassword ID="ChangePassword1" runat="server">
					</asp:ChangePassword>
				</ContentTemplate>
			</AjaxControlToolkit:TabPanel>
		</AjaxControlToolkit:TabContainer>
	</form>
 
 
	protected void Page_Load (object sender, EventArgs e)
	{
		ProfileNameLabel.Text = "ragi";
	}

Open in new window

0
 
HarleySkaterAuthor Commented:
System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="App_Web_tdujeadl"
  StackTrace:
       at Settings.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Administrator.ACFUNDING.000\My Documents\AG\AG Website\Settings\Settings.aspx.vb:line 19
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:
 

line 19 in my code was just this : ProfileNameLabel.Text = "ragi"
0
 
Anurag ThakurTechnical ManagerCommented:
cant really understand why you are getting the error becaue the same code is running fine for me as i am able to see  ragi in the text box
0
 
HarleySkaterAuthor Commented:
ok so I am leaning towards there being a problem referencing it because of the object execption.  

so I tried to take ProfileNameLabel.Text = "ragi" and move it outside of the tab container.  

What a surprise!!!!! the vb code threw the same execption!!!!!! sooOoO im like wth...

Then I move it to outside of the login view!  and wa-la  everything works.

Why would putting labels inside a login view cause this kind of problem??? I don't understand what is going on hereeeeeeeeeee!!!!  
0
 
HarleySkaterAuthor Commented:
Ok so I am just going to redirect the user if they aren't authenticated from the vb code, I took out the loginview control and everything is nice now :D

Your getting the points for helping me out though!!!!! THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

LoL this was kind of a wierd one :D

noone suspected the login view hahahah thaty shiesty login view...  
I have loginviews all over the place toooo I wonder why this ones acting so stupid
0
 
HarleySkaterAuthor Commented:
Thanks for the great effort!  :D!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 11
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now