Trido
Trido

Reputation: 545

Does not exist in current context

I have the below code:

CODE BEHIND:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;

namespace TestApp2
{
    public partial class hookload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Rig_ID"].Equals(1))
                MultiView1.ActiveViewIndex = 0;
            else if (Request.QueryString["Rig_ID"].Equals(2))
                MultiView1.ActiveViewIndex = 1;
            else if (Request.QueryString["Rig_ID"].Equals(3))
                MultiView1.ActiveViewIndex = 2;
            else if (Request.QueryString["Rig_ID"].Equals(4))
                MultiView1.ActiveViewIndex = 3;
            else if (Request.QueryString["Rig_ID"].Equals(5))
                MultiView1.ActiveViewIndex = 4;
        }
    }
}

And this is my aspx file:

<%@ Page Title="Shannons Proof of Concept Rig Dashboard" Language="C#" MasterPageFile="~/Site.master"
    AutoEventWireup="true" CodeBehind="hookload.aspx.cs" Inherits="TestApp2._Default" %>

<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:MultiView ID="MultiView1" runat="server">
        <asp:View ID="View1" runat="server">
            <asp:SqlDataSource ID="SqlDataSource27" runat="server" ConnectionString="<%$ ConnectionStrings:RigDashConnectionString1 %>"
                SelectCommand="SELECT TOP (30) tbl_rig.name, tbl_stats.Timestamp AS Expr1, tbl_stats.HookLoad, tbl_stats.Rig_ID FROM tbl_rig INNER JOIN tbl_stats ON tbl_rig.rig_id = tbl_stats.Rig_ID WHERE (tbl_stats.Rig_ID = 2) ORDER BY Expr1 DESC">
            </asp:SqlDataSource>
            <h2>
                Rig Hook Load Stats - Previous 10 minutes</h2>
            <p>
                <asp:Chart ID="Chart25" runat="server" DataSourceID="SqlDataSource27" Width="900px"
                    Height="500px" Style="margin-top: 5px" Palette="EarthTones">
                    <Series>
                        <asp:Series Name="Rig 24 Hook Load" XValueMember="Expr1" XValueType="Time" YValueMembers="HookLoad"
                            Legend="Legend" YValuesPerPoint="1" ChartType="Line">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                            <Area3DStyle Enable3D="True" LightStyle="Realistic" WallWidth="0" />
                        </asp:ChartArea>
                    </ChartAreas>
                    <Legends>
                        <asp:Legend Name="Legend" Title="Legend">
                        </asp:Legend>
                    </Legends>
                </asp:Chart>
            </p>
        </asp:View>
        <asp:View runat="server">
            <asp:SqlDataSource ID="SqlDataSource28" runat="server" ConnectionString="<%$ ConnectionStrings:RigDashConnectionString1 %>"
                SelectCommand="SELECT TOP (30) tbl_rig.name, tbl_stats.Timestamp AS Expr1, tbl_stats.HookLoad, tbl_stats.Rig_ID FROM tbl_rig INNER JOIN tbl_stats ON tbl_rig.rig_id = tbl_stats.Rig_ID WHERE (tbl_stats.Rig_ID = 3) ORDER BY Expr1 DESC">
            </asp:SqlDataSource>
            <h2>
                Rig Hook Load Stats - Previous 10 minutes</h2>
            <p>
                <asp:Chart ID="Chart26" runat="server" DataSourceID="SqlDataSource28" Width="900px"
                    Height="500px" Style="margin-top: 5px" Palette="EarthTones">
                    <Series>
                        <asp:Series Name="Rig 21 Hook Load" XValueMember="Expr1" XValueType="Time" YValueMembers="HookLoad"
                            Legend="Legend" YValuesPerPoint="1" ChartType="Line">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                            <Area3DStyle Enable3D="True" LightStyle="Realistic" WallWidth="0" />
                        </asp:ChartArea>
                    </ChartAreas>
                    <Legends>
                        <asp:Legend Name="Legend" Title="Legend">
                        </asp:Legend>
                    </Legends>
                </asp:Chart>
            </p>
        </asp:View>
        <asp:View runat="server">
            <asp:SqlDataSource ID="SqlDataSource29" runat="server" ConnectionString="<%$ ConnectionStrings:RigDashConnectionString1 %>"
                SelectCommand="SELECT TOP (30) tbl_rig.name, tbl_stats.Timestamp AS Expr1, tbl_stats.HookLoad, tbl_stats.Rig_ID FROM tbl_rig INNER JOIN tbl_stats ON tbl_rig.rig_id = tbl_stats.Rig_ID WHERE (tbl_stats.Rig_ID = 5) ORDER BY Expr1 DESC">
            </asp:SqlDataSource>
            <h2>
                Rig Hook Load Stats - Previous 10 minutes</h2>
            <p>
                <asp:Chart ID="Chart27" runat="server" DataSourceID="SqlDataSource29" Width="900px"
                    Height="500px" Style="margin-top: 5px" Palette="EarthTones">
                    <Series>
                        <asp:Series Name="Rig 22 Hook Load" XValueMember="Expr1" XValueType="Time" YValueMembers="HookLoad"
                            Legend="Legend" YValuesPerPoint="1" ChartType="Line">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                            <Area3DStyle Enable3D="True" LightStyle="Realistic" WallWidth="0" />
                        </asp:ChartArea>
                    </ChartAreas>
                    <Legends>
                        <asp:Legend Name="Legend" Title="Legend">
                        </asp:Legend>
                    </Legends>
                </asp:Chart>
            </p>
        </asp:View>
    </asp:MultiView>
    <p>
        <a href="..\default.aspx">< Go Back</a>
    </p>
</asp:Content>

Now my problem is that when I try to run this, I get the message 'The name 'MultiView1' does not exist in the current context'. I really don't understand why I am getting this error, but I am also a noob so it isn't surprising. :) Basically, I have a asp:gridview table on the first page and I am trying to pass parameters to then be processed by this page so when someone clicks the link for ~\charts\hookload.aspx?Rig_ID=2, it processes MultiView Index 1 so it displays a chart of relevant data as described by the SQL Query.

This has been the only way I have found so far to do this so if anyone else has a better idea, believe me I am all ears. I have struggled to locate an answer to this, mainly because I don't know what keywords to search for. Any help would be appreciated.

Upvotes: 0

Views: 7760

Answers (2)

nunespascal
nunespascal

Reputation: 17724

Inherits attribute of your page must refer to name of your backing class.

Correct your Inherits as follows:

<%@ Inherits="TestApp2.hookload" Page Title="Shannons Proof of Concept Rig Dashboard" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="hookload.aspx.cs"  %>

Happens when you change a class name and forget to correct it in the aspx file.

Upvotes: 1

aravind
aravind

Reputation: 535

<%@ Page Title="Shannons Proof of Concept Rig Dashboard" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="hookload.aspx.cs" Inherits="TestApp2._Default" %>

Your page inherits wrongly Inherits="TestApp2._Default"

Upvotes: 1

Related Questions