Solved

define variables in .aspx.cs and use in .aspx

Posted on 2007-11-16
1
9,309 Views
Last Modified: 2008-02-01
I have defined a string variable in .aspx.cs file, and I want to use that variable in the .aspx file.

In .aspx.cs file I have:

private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  string Test = "------ test -------";
            }

In .aspx file I have:

<%@ Page language="c#" Codebehind="WebForm7.aspx.cs" AutoEventWireup="false" Inherits="FileEditor2.WebForm7" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
      <HEAD>
            <title>WebForm7</title>
            <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" Content="C#">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
            
            
            <%=Test%>
            
            
            
            </form>
      </body>
</HTML>
0
Comment
Question by:fippif
1 Comment
 
LVL 17

Accepted Solution

by:
xDJR1875 earned 250 total points
ID: 20301345
You would need to make it a public variable in the scope of the page class.
You created a local variable in the page load function.

You should then be able to refer to that variable in the aspx file server side code.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

20 Experts available now in Live!

Get 1:1 Help Now