aspx.cs内在哪怎么定义变量,使其可以在整个aspx.cs内可用?麻烦说详细点啊~~

解决方案 »

  1.   

    class default : Page
    {
        private int x;
        ...
    }
      

  2.   

    LZ 可以将值存放在session中
    在任何地方都可以用了
      

  3.   

    没有页面跳转,只是在这一个aspx.cs文件里用,而且想要定义的是一个数组————我想做的是在数据库中读出所有的经纬度,然后再在谷歌地图上显示,赋经纬度的地方,写reder不对啊
      

  4.   

    定义在class里面,方法外面···
      

  5.   

    [Quote=引用 7 楼 zyloveyrf 的回复:]LZ方便多话将代码贴出来
     
      

  6.   

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Collections.Generic;
     
    namespace S.Sams.GoogleMap.Web
    {
           /// <summary>
        /// MapPageBase 处理了 // onload="initialize()" onunload="GUnload()" 这两个事件, 如果不使用继承, 请自行处理该事件!
        /// </summary>
        public partial class Default : MapPageBase
        {        #region 数据初始化
            private string AppID
            {
                get { return appid.Text; }
            }        private Init GetSystemInit
            {
                get
                {
                    Init init = new Init(showmymap2.Text, int.Parse(scaleint.Text), MapType.Normal, MapControl.Full);
                    init.EnabledScrollWheelZoom = EnabledScrollWheelZoom.Checked;
                    init.IsMapScale = mapscale.Checked;
                    init.IsMapView = mapview.Checked;
                    init.IsMapType = IsMapType.Checked;
                    init.IsMapControls = IsMapControls.Checked;
                    init.IsShowCenterMsg = IsShowCenterMsg.Checked;
                    init.MapViewWidth = int.Parse(MapViewWidth.Text);
                    init.MapViewHeight = int.Parse(MapViewHeight.Text);
                    init.IsAddLine = IsAddLine.Checked;
                    init.IsAddLineEnd = IsAddLineEnd.Checked;
                    init.AddLine16Color = AddLine16Color.Text;
                    init.AddLineWidth = int.Parse(AddLineWidth.Text);
                    init.Customlabel = new CustomLabel() { 
                        isEnabledCusstomLabel = isEnabledUserCusstom.Checked, 
                        isOnlyOnePoint = isUsePointOne.Checked, 
                        PointMsg = UsePointOneMsg.Text, 
                        JavascriptFunction = FunctionName.Text, 
                        isClickShowMsg = isClickShowMsg.Checked 
                    };
                    init.EnableGoogleBar = EnableGoogleBar.Checked;
                    init.EnableGoogleBarShow = EnableGoogleBarShow.Checked;
                    return init;
                }
            }            private List<Label> GetLabels
                {
                    get
                {
               //在这里想从数据库里调值赋值,数据库中存的数据个数不定                return new List<Label>()                 {
                        new Label(){ 
                            TabMsg = new List<Msg>() {
                                        new Msg("环境", L1_msg.Text),
                                        new Msg("饮食", "仅次于一般"),
                                        new Msg("一起飞","")
                                    },
                            IsCenter = L1_iscenter.Checked,
                            LabelImage = L1_img.Text,
                            X = double.Parse(L1_x.Text),
                            Y = double.Parse(L1_y.Text),
                            ZoomIn = int.Parse(L1_zoomin.Text),
                            IsShowMapView = L1_mapview.Checked,
                            Visible = L1_visible.Checked,
                            MsgMaxTitle = L1_maxtitle.Text,
                            MsgMaxContent = L1_maxcontent.Text
                        },
                        new Label(){ 
                            Msg=L2_msg.Text,
                            IsCenter = L2_iscenter.Checked,
                            LabelImage = L2_img.Text,
                            X = double.Parse(L2_x.Text),
                            Y = double.Parse(L2_y.Text),
                            ZoomIn = int.Parse(L2_zoomin.Text),
                            IsShowMapView = L2_mapview.Checked,
                            Visible = L2_visible.Checked,
                            MsgMaxTitle = L2_maxtitle.Text,
                            MsgMaxContent = L2_maxcontent.Text
                        }
                    
                        }
                    };
                }
            }                private List<MapLine> GetMapLines
                    {
                        get {
                    return new List<MapLine>(){new MapLine() {
                        Labels = GetLabels,
                        LineWidth = int.Parse(GetMapLines_Width.Text),
                        Color16Code = GetMapLines_Color.Text}
                    };
                }
            }        #endregion
    //……}
      

  7.   

    /// <summary>
    /// cs后台文件,针对页面事件进行响应
    /// </summary>
    public partial class SignWeb : System.Web.UI.Page
    {
        //声明页面元素
        protected string  strXuHao;
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }此处的strXuHao定义的变量,即可在整个.cs里使用。
    并且,在前台.aspx内可获取,使用 <%=strXuHao%>
      

  8.   

    /// <summary>
    /// cs后台文件,针对页面事件进行响应
    /// </summary>
    public partial class SignWeb : System.Web.UI.Page
    {
      //声明页面元素
      protected string strXuHao;
      protected void Page_Load(object sender, EventArgs e)
      {
      }
    }此处的strXuHao定义的变量,即可在整个.cs里使用。
    并且,在前台.aspx内可获取,使用 <%=strXuHao%>