Solved

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

Posted on 2008-10-27
17
1,248 Views
Last Modified: 2012-05-05
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
Comment
Question by:HarleySkater
  • 11
  • 6
17 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22815467
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
 
LVL 1

Author Comment

by:HarleySkater
ID: 22815663
it doesn't see it I think, because it has to reference the ajax tab container and then the label
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22815842
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
 
LVL 1

Author Comment

by:HarleySkater
ID: 22816165
hmmmmmmm I get this error

Error      1      Type 'AjaxControlToolkit.TabPanel' does not have a public property named 'UpdatePanel'.            
0
 
LVL 1

Author Comment

by:HarleySkater
ID: 22816229
i am using asp.net 3.5 also :P
0
 
LVL 1

Author Comment

by:HarleySkater
ID: 22816349
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
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22818967
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
 
LVL 1

Author Comment

by:HarleySkater
ID: 22820884
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22821012
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
 
LVL 1

Author Comment

by:HarleySkater
ID: 22821078
<%@ 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
 
LVL 1

Author Comment

by:HarleySkater
ID: 22821282
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22821298
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
 
LVL 1

Author Comment

by:HarleySkater
ID: 22821386
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
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 500 total points
ID: 22821451
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
 
LVL 1

Author Comment

by:HarleySkater
ID: 22821537
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
 
LVL 1

Author Comment

by:HarleySkater
ID: 22821741
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
 
LVL 1

Author Closing Comment

by:HarleySkater
ID: 31510435
Thanks for the great effort!  :D!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now