I can not find an answer for this scenario here: I have an ASP.NET project using C # is. I am loading data (user name, email, etc ...) from SQL database to C # (using ADO). I am loading data into a class file in a static global variable in my App_Data folder. I need to be able to insert the username in the ASP.NET label on the page while loading.
In PHP, I will do this like this:
Here is an update for some more detail. I tried what you suggested. My page load function is in the file named Ranked. ASPCAC and ranks in the table below. This idea is to list a group of users I have received from the database. I threw it in 'myLabel', just to check it. Right now, without declaring 'myLabel' behind my code, these errors do not exist 'myLabel' in the current context if I declare 'myLabel' using the FindControl () function, I get a runtime exception that 'MyLabel' is not set for an object instance
Here is the code:
protected page_load (object sender, eventAgds E) {if (! Page. ) {Label myLabel = this.FindControl ("myLabel") as a label; MyLabel.Text = "My Text"; }} & Lt; Table & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; Th & gt; Name & lt; / Th & gt; & Lt; Th & gt; Score & lt; / Th & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Name & lt; / TD & gt; & Lt; TD & gt; Score & lt; / TD & gt; & Lt; / TR & gt; & Lt ;! - Current user - & gt; & Lt; TR & gt; & Lt; Td> & Lt; Asp: label id = "current username" run = "server" & gt; & Lt; / Asp: label & gt; & Lt; / Td> & Lt; Td> & Lt; ASP: Labels ID = "Current user score" run = "server" & gt; & Lt; / Asp: label & gt; & Lt; / Td> & Lt; Td> & Lt; Asp: label id = "myLabel" runat = "server" /> & Lt; / Td> & Lt; / TR & gt; & Lt ;! - End current user - & gt; & Lt; / Tbody & gt; & Lt; / Table & gt;
For this label:
& lt ; Asp: label id = "myLabel" runat = "server" /> In the code behind the use (C #):
myLabel.Text = "My Text";
Update (after the updated question):
You do not have to use the FindControl - this is complete The line is overlaid: Label myLabel = this.FindControl ("myLabel") as the label; MyLabel.Text = "My Text"; should be:
myLabel.Text = "My Text"; The Visual Studio Designer should create a file with all server-side controls that are already correctly added to the class ( RankPage.aspx.designer.cs file, by default). You are talking about the RankPage.cs file - the way the Visual Studio name is, it is RankPage.aspx.cs . How are you adding these files together?
Comments
Post a Comment