Category Archives: TreeView

Treeview - SelectedNodeChanged event never fired

Hi

I have a Treeview control on my master page, the treeview is bound to a sitemap.

<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" NodeIndent="10" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" ShowCheckBoxes="All" AutoGenerateDataBindings="False">
   <DataBindings
>
      <asp:TreeNodeBinding DataMember="SiteMapNode" NavigateUrl="~/Default.aspx" NavigateUrlField="Url" Text="Title" TextField="Title" ToolTipField="Description" Value="Title"
/>
   </DataBindings
>
</asp:TreeView
>

But when I select a node in the view, the SelectedNodeChanged event isn't fired. The site just navigates to the new page.
ViewState is enabled.

Thanks for your help in advance.

Hi,
  The TreeView can do either 1 of 2 things.  Navigate or postback.  If it navigates, then you simply load the next page regardless of what page it is (the same page or different).  If it posts back, then it fires events on the same page.  Since you have navigate urls, that implies you are navigating and you won't get postback events.
--
Danny

Hi Danny

Thanks for your reply. I've reached the same conclusion, after several of hours debugging my app and discusses with colleges :)
Shame we don't live in the same timezone, you could have safed me a lot of wasted time.
Thanks again

///Rune 

I've searched numerous pages about this issue, and this post seems to sum-up the consensus.

Surely a TreeView and web.sitemap is one of the most common approaches to Navigation in ASP.NET 2005 (notice that it's on the "Navigation" tab in the toolbar). So why are navigating and coding (postback) mutually exclusive?

I used to get around this oddity of not having a SelectedNodeChange event (before the RTM) using the Page.SaveStateComplete event like this:

If masterTreeView.SelectedValue <> "" Then
   masterTreeView.SelectedNode.Expand()
End If

And it worked okay; but now even that won't work. It's like MS is going out of their way to make things more difficult. All I want is the exact same functionality as the +/- signs, but without seeing the symbols (our designers decision, not mine), but you're saying this is impossible now?

Well, after a few hours and way more code than I would have liked, I have the previous functionality back again. I'm basically doing all the expand/collapse functionality on my own in the SaveStateComplete. If you don't want to use the +/- symbols, you're in trouble.

yekcim1125

Surely a TreeView and web.sitemap is one of the most common approaches to Navigation in ASP.NET 2005 (notice that it's on the "Navigation" tab in the toolbar). So why are navigating and coding (postback) mutually exclusive?

Here's an example that might help explain this.  Lets say you have a TreeView on a page at:  http://www.msn.com/testpage.aspx  And lets say you have another (or even an identically coded) TreeView on a page at:  http://www.microsoft.com/somepage.aspx.  Lets say the first TreeView has a node with a NavigateUrl=http://www.microsoft.com/somepage.aspx.  If you are viewing the msn page and you click on the link to the microsoft.com page, would you expect that a SelectedNodeChanged event fires on the msn site?  the microsoft site?  neither? 

I think the obvious answer is neither.  There isn't any difference between this scenario and navigating to another page on the same site except that this is more clear (I think).  That is why navigation and postbacks are mutually exclusive.  Submitting a form and navigating to a new url are separate actions. 

If you think it should act a different way, I'd be happy to listen to your feedback.  Thanks.
--
Danny 

 

Is there a way to make the treeview generate events knowingly instead of on postback?

Basically I want to use the treeview the way you do when you install Visual Studio 2005 (tri-state checkbox). I think the treeview lacks some flexibility. Is there a way to enable event firing programmatically.

I am using the TreeView in ASP .Net 2.0

I would like to be able to browse a document via the NavigateUrl on a treenode in a separate frame to the treeview, as specified by the Target="blah" on the node. I would then like to be able to indicate the currently selected node, which should be the node that was navigated/selected.

At the moment I can only indicate the parent of the node. When there are many children, I cannot indicated the currently navigated/selected node

What I don't understand is; Why can't the Select events fire if the target is specifying a different location(frame)  to the treeview (frame)?

Without this feature it seems impossible to indicate to the user which document is the currently navigated/selected node.

Regards

Mike

first, same level nodes must have different values to distinguish selected node. Else treeview shows parent node selected.

second, if you use navigate url treeview works in navigate mode and disables selection events. So you cannot determine the selected tree node.

To solve this you can try to populate tree node texts with javascript that populates some hidden field values at the target frame...

Extra information about treenode class : http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.treenode.aspx

Ozan K. BAYRAM

Thanks so much for this post.  I spent several hours fighting this issue and was pretty close to giving up.  A real world example that worked!

 

 

 

Can you answer a simple question?  What event do I need to register to handle this?

protected

virtual void SMI_CommandTest(Object sender, TreeNodeEventArgs e)

 

[RESOLVED] url routing with asp.net 3.5 or 4

Hi I need to fix url routing different from the basics that is builtin in the framework...Basically I need it to go unlimited levels deep the same as the product catalog can when using the parent relation for each category added.

does anyone have a good sample for webforms of how I could do it...I want URL listings to look like this

www.mydomain.com/category/category2/category3/ or like this www.mydomain.com/category/category2/category3.aspx

and details URL looking like this

www.mydomain.com/category/category2/category3/title-of-article-or-productname.aspx

 

Thanks,

 

I don't know about version 3.5 but in 4.0 this should be okay.

I would just use the standard ASP.NET 4.0 routing and implement them like this:

routes.MapPageRoute("", "/Category/{cat2}", "~/Category.aspx");

<div>

routes.MapPageRoute("", "/Category/{cat2}/{cat3}", "~/Category.aspx");

</div><div>

routes.MapPageRoute("", "/Category/{cat2}/{cat3}/{cat4}", "~/Category.aspx");

The depth is not unlimited but I'm guessing there will be a limit to the number of levels you'll need to go.

</div><div>
</div>

This tutorial might help you....

http://msdn.microsoft.com/en-us/library/cc668201.aspx

Thanks.

this might help you  http://msdn.microsoft.com/en-us/magazine/dd347546.aspx#id0070003

thanks for your answers guys....these examples covers the basics...which is quite easy to implement. Im looking for something that can handle more complex structures and preferably can come up automatically as categories are added to the database without any manual tampering in global.asax

Basically I want to know if it is possible to dynamically generate the rounting table without registering them in Global.asax.

If not I will have to register 24 routes for the product catalogue (6 base routes with limit to 3 subcategories deep) itself and then a few for other kind of pages so a total of 26 routes...and it will have to be maintained everytime a new base category is registered then I have to register 4 new routes...it wont happend often but does anyone have any ideas...?

Basically I want URL like this

www.mywebsite.com/{category}/{category1}/{category2}/{category3}/{product}/

No fixed root pointer...any ideas?

I have temporarily fixed it with a route /catalog/ but it is not wanted  

www.mywebsite.com/catalog/{category}/{category1}/{category2}/{category3}/{product}/

IS this possible in ASP.NET or is the global.asax a necessary evil?

Hi,

manga75

I have temporarily fixed it with a route /catalog/ but it is not wanted  

www.mywebsite.com/catalog/{category}/{category1}/{category2}/{category3}/{product}/

IS this possible in ASP.NET or is the global.asax a necessary evil?

 

Please check the sample below,hope this helps.

http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx

 

thanks but for if the application was running in MVC this would never have been a problem...it is webforms as posted in the question.

Hi,

manga75

...it is webforms as posted in the question.

 

Please try this:

Using Routing With WebForms

ASP.NET 4.0 WebForms Routing

How to: Use Routing with Web Forms

Hope this helps.

Thank you but I allready know the basics what Im looking for is how to generate the routes automatically from the database so I dont have to register them manually so it work truly like a datadriven site.

I have a database categories table that has a parent child relation so I can build and unlimited amount of subcategories

id (int)
categoryname (varchar)
active (bit)
rawurl (varchar) 
parent int (fk id)

id category active rawurl parent
1 sport TRUE /1/ null
2 winter TRUE /1/2/ 1
3 hockey TRUE /1/2/3/ 2
4 skates TRUE /1/2/3/4/ 3
5 Junior TRUE /1/2/3/4/5/ 4
6 Pro TRUE /1/2/3/4/6/ 4
7 Practise TRUE /1/2/3/4/6/7/ 6

I allready generate the treeview and store it in cache and thats basically what I want to be able to do with the routing aswell so the routing can reflect the database.

<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;" id="_mcePaste">
id category active rawurl parent
1 sport TRUE /1/ null
2 winter TRUE /1/2/ 1
3 hockey TRUE /1/2/3/ 2
4 skates TRUE /1/2/3/4/ 3
5 Junior TRUE /1/2/3/4/5/ 4
6 Pro TRUE /1/2/3/4/6/ 4
7 Practise TRUE /1/2/3/4/6/7/ 6
</div>

[RESOLVED] Sending Data Between Iframes.

Hi

I've got a situation where there is a page with 3 iframes. The first frame contains a TreeView, the second a GridView which is dependent on the selected node of the Treeview in frame 1 and the third frame contains labels with information also dependent on the TreeView in the first frame.

My problem is, how do I pass information from the first frame to the others? Can I access information about the selected node in JavaScript, pass it to another frame and then do a postback with the info as an argument?


Thanks

Hi

You can see explaination here from

sharing variables between windows and frames

accessing variables from one frame to another

Now, sharing variables between frames is not really any different than sharing them between windows. All you need is a reference to the frame object.

For example, if a window has two frames, the first frame can access a variable in the second frame using the following expression:

Example: first frame accessing second frame's variable

parent . frames [1] .
variable_name

Similarly, the second frame can access variables in the first frame through the following expression:

Example: second frame accessing first frame's variable

parent . frames [0] . 
variable_name

As illustrated in these examples, frames can obtain references to neighboring frames through the parent window's

frames []
property. Don't forget that the first frame in this array is indexed with 0, not 1.


Regards

shabir

Hi

Thanks, I have no problem passing JavaScript variables between frames, the problem is how do I pass info from the server control to JavaScript? I've been experimenting with the IscriptControl interface, I'd like to bind a function to the window's onload event so after the user clicks on the TreeFrame it does a postback and when the window has finished loading it can pass the selected node onto the other frame with the gridview.

Regards

Hi,

You can consider to pass value between Iframe by using QueryString in Iframe src property.

Like:

<iframe id="frm" src="page.aspx?p1=1">

Or code behind:

Iframe.Attributes["src"] = "page.aspx?p1=" + HttpUtility.UrlEncode(p1);

You can check this link:

http://www.codeproject.com/KB/aspnet/IFrameParams.aspx

Hope this can help you.

[RESOLVED] Can't see TreeView from code-behind code page

I have an aspx page with a TreeView control named TreeView1.  in the Page_Load method I am trying to collapse all nodes except for the current node.  I used this code in the Page_Load method:

TreeView1.CollapseAllNodes();
TreeView1.SelectedNode.Expand();

When I try to run this I get the following error:

CS0103: The name 'TreeView1' does not exist in the current context

I am using a .NET 2.0 website and can't seem to reference controls in my .aspx page from within my code-behind page. I tried adding an instance of the TreeView before my Page_Load method call in the code behind, but, it still doesn't create a reference.  What am I missing?

Assuming you haven't misspelled "TreeView1", it looks to me like your .aspx isn't connected to your code-behind.

I'd try:

  • rebuilding the entire solution
  • closing Visual Studio, rebooting computer [please, don't say it, I know, but sometimes...]
  • excluding the page in question from your solution, and then adding it in as a new item, copying markup and code from old to new

If all that fails, could you please post all your markup and code - the entirel page?  With that, I'll have a better chance at spotting something. 

(It makes things a lot more readable if you use the Insert Code tool. If you need instructions, see my How to use the Forums' "Insert Code" tool. post.) 

I have tried your suggestions and didn't get much further.  I think I am missing something a little less complex than that.  This is a .NET 2.0 site.  When I tried to reference the controls in the code-behind page I used this approach:

TreeView TreeView1 = (TreeView)Page.FindControl("TreeView1");


However, when I tried to use tab completion after typing (TreeView)Page. it would not provide the FindControl method.  Is there something about the project config I need to look at?  I have never had this much difficulty referencing code from the code-behind.

FindControl executes at run-time, and should only be used for dynamically created controls, like those inside ItemTemplates, etc.

Assuming that you've created TreeView1 using basic markup, you should be able to replace the above line with this "TreeView TreeView1 = this.TreeView1;".   Better yet, you should be able to refer directly to this.TreeView1 wherever you need to.

If this doesn't help, would you mind posting all your relevant markup and code?

The following page doesn't specifically look for TreeView1, but, it's the same problem.  I cannot see controls from the code-behind.  Here is the .aspx code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="locked_batches.aspx.cs" Inherits="Environments_Model_locked_batches" Src="~/Environments/Model/locked_batches.aspx.cs" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../../Stylesheets/default.css" rel="Stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="top"><span class="fiserv">eFichency</span> Reference</div>
        <div id="preferences">
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                onselectedindexchanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
        </div>
        <div id="content">
            <table>
                <tr>
                    <td>
                        <asp:SiteMapDataSource ID="SiteMapDataSource" runat="server" />
                        <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource"
                            ImageSet="Msdn" NodeIndent="10">
                            <HoverNodeStyle BackColor="#CCCCCC" BorderColor="#888888" BorderStyle="Solid"
                                Font-Underline="True" />
                            <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
                                HorizontalPadding="5px" NodeSpacing="1px" VerticalPadding="2px" />
                            <ParentNodeStyle Font-Bold="False" />
                            <SelectedNodeStyle BackColor="White" BorderColor="#888888" BorderStyle="Solid"
                                BorderWidth="1px" Font-Underline="False" HorizontalPadding="3px"
                                VerticalPadding="1px" />
                        </asp:TreeView>
                    </td>
                    <td>
			            Find below information on locked batches.<br/><br/>
                        <asp:Label ID="LabelCount" runat="server" Text="The record count is: "></asp:Label><br /><br />
                        <asp:SqlDataSource ID="sqlDataSource" runat="server"
                            SelectCommand="SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received))"
                            connectionString="<%$ ConnectionStrings:ModelFOTNIndexConnectionString %>"
                            onselected="SqlDataSource_Selected">
                            <SelectParameters>
                                <asp:Parameter DefaultValue="10" Name="CurrentEventTypeID" Type="Int32" />
                                <asp:Parameter DefaultValue="2" Name="Received" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
                            AllowSorting="True" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
                            BorderWidth="1px" CellPadding="4" DataSourceID="SqlDataSource"
                            ForeColor="Black" GridLines="Vertical" PageSize="15" Visible="True"
                            onpageindexchanged="GridView1_PageIndexChanged" onsorted="GridView1_Sorted" >
                            <RowStyle BackColor="#F7F7DE" />
                            <EmptyDataTemplate>
                                No records were found.
                            </EmptyDataTemplate>
                            <FooterStyle BackColor="#CCCC99" />
                            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
                            <AlternatingRowStyle BackColor="White" />
                        </asp:GridView>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    </form>
</body>
</html>


And, here is the code-behind:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class Environments_Model_locked_batches : System.Web.UI.Page
{
		protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList1.DataSource = IndexDataSource(sqlDataSource);
            DropDownList1.DataBind();
            DropDownList1.Items.Insert(0, "Choose a filter string");
        }
    }

    protected ArrayList IndexDataSource(SqlDataSource sqlDataSource)
    {
        ArrayList indexArrayList = new ArrayList();
        DataTable indexDataTable = new DataTable();
        DataView indexDataView = new DataView();

        indexDataView = (DataView)sqlDataSource.Select(DataSourceSelectArguments.Empty);
        indexDataTable = indexDataView.ToTable();

        foreach (DataRow dataRow in indexDataTable.Rows)
        {
            string[] rowIndex = (dataRow["UserBatchName"].ToString()).Split(' ');
            foreach (string word in rowIndex)
            {
                if (!indexArrayList.Contains(word))
                {
                    indexArrayList.Add(word);
                }
            }
        }

        indexArrayList.Sort();

        return indexArrayList;
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "Choose a filter string")
        {
            GridView1.Visible = true;
            GridView1.DataBind();
        }
        else
        {
            sqlDataSource.SelectParameters.Clear();
            sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
            sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
            GridView1.DataBind();
        }
    }

    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "Choose a filter string")
        {
            GridView1.Visible = true;
            GridView1.DataBind();
        }
        else
        {
            sqlDataSource.SelectParameters.Clear();
            sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
            sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
            GridView1.DataBind();
        }
    }

    protected void GridView1_Sorted(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "Choose a filter string")
        {
            GridView1.Visible = true;
            GridView1.DataBind();
        }
        else
        {
            sqlDataSource.SelectParameters.Clear();
            sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
            sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
            GridView1.DataBind();
        }
    }
    protected void SqlDataSource_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        if (DropDownList1.SelectedValue == "Choose a filter string")
        {
            LabelCount.Text = "The record count for all records is: " + e.AffectedRows.ToString();
        }
        else
        {
            LabelCount.Text = "The record count for " + DropDownList1.SelectedValue + " is: " + e.AffectedRows.ToString();
        }

        if (e.Exception != null)
        {
            LabelCount.Visible = false;
            GridView1.EmptyDataText = e.Exception.Message;
        }
    }
}


When I try to run the page, I get this:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0103: The name 'DropDownList1' does not exist in the current context

Source Error:

 

Line 15:         if (!IsPostBack)
Line 16:         {
Line 17:             DropDownList1.DataSource = IndexDataSource(sqlDataSource);
Line 18:             DropDownList1.DataBind();
Line 19:             DropDownList1.Items.Insert(0, "Choose a filter string");
 

Source File: c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs    Line: 17 



Show Detailed Compiler Output:


c:\windows\system32\inetsrv> "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /out:"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\f3c5e0e5\97ac95d6\App_Web_locked_batches.aspx.cs.d4225d1c.bewrivva.dll" /debug- /optimize+ /w:4 /nowarn:1659;1699;1701  "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\f3c5e0e5\97ac95d6\App_Web_locked_batches.aspx.cs.d4225d1c.bewrivva.0.cs" "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\f3c5e0e5\97ac95d6\App_Web_locked_batches.aspx.cs.d4225d1c.bewrivva.1.cs"


Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.3053
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(17,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(17,56): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(18,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(19,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(51,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(53,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(54,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(58,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(59,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(59,65): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(60,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(61,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(67,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(69,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(70,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(74,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(75,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(75,65): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(76,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(77,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(83,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(85,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(86,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(90,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(91,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(91,65): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(92,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(93,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(98,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(100,13): error CS0103: The name 'LabelCount' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(104,13): error CS0103: The name 'LabelCount' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(104,57): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(109,13): error CS0103: The name 'LabelCount' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(110,13): error CS0103: The name 'GridView1' does not exist in the current context

 



Show Complete Compilation Source:


Line 1:    using System;
Line 2:    using System.Collections;
Line 3:    using System.Collections.Generic;
Line 4:    using System.Data;
Line 5:    using System.Data.SqlClient;
Line 6:    using System.Web;
Line 7:    using System.Web.UI;
Line 8:    using System.Web.UI.HtmlControls;
Line 9:    using System.Web.UI.WebControls;
Line 10:   
Line 11:   public partial class Environments_Model_locked_batches : System.Web.UI.Page
Line 12:   {
Line 13:   		protected void Page_Load(object sender, EventArgs e)
Line 14:       {
Line 15:           if (!IsPostBack)
Line 16:           {
Line 17:               DropDownList1.DataSource = IndexDataSource(sqlDataSource);
Line 18:               DropDownList1.DataBind();
Line 19:               DropDownList1.Items.Insert(0, "Choose a filter string");
Line 20:           }
Line 21:       }
Line 22:   
Line 23:       protected ArrayList IndexDataSource(SqlDataSource sqlDataSource)
Line 24:       {
Line 25:           ArrayList indexArrayList = new ArrayList();
Line 26:           DataTable indexDataTable = new DataTable();
Line 27:           DataView indexDataView = new DataView();
Line 28:   
Line 29:           indexDataView = (DataView)sqlDataSource.Select(DataSourceSelectArguments.Empty);
Line 30:           indexDataTable = indexDataView.ToTable();
Line 31:   
Line 32:           foreach (DataRow dataRow in indexDataTable.Rows)
Line 33:           {
Line 34:               string[] rowIndex = (dataRow["UserBatchName"].ToString()).Split(' ');
Line 35:               foreach (string word in rowIndex)
Line 36:               {
Line 37:                   if (!indexArrayList.Contains(word))
Line 38:                   {
Line 39:                       indexArrayList.Add(word);
Line 40:                   }
Line 41:               }
Line 42:           }
Line 43:   
Line 44:           indexArrayList.Sort();
Line 45:   
Line 46:           return indexArrayList;
Line 47:       }
Line 48:   
Line 49:       protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
Line 50:       {
Line 51:           if (DropDownList1.SelectedValue == "Choose a filter string")
Line 52:           {
Line 53:               GridView1.Visible = true;
Line 54:               GridView1.DataBind();
Line 55:           }
Line 56:           else
Line 57:           {
Line 58:               sqlDataSource.SelectParameters.Clear();
Line 59:               sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
Line 60:               sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
Line 61:               GridView1.DataBind();
Line 62:           }
Line 63:       }
Line 64:   
Line 65:       protected void GridView1_PageIndexChanged(object sender, EventArgs e)
Line 66:       {
Line 67:           if (DropDownList1.SelectedValue == "Choose a filter string")
Line 68:           {
Line 69:               GridView1.Visible = true;
Line 70:               GridView1.DataBind();
Line 71:           }
Line 72:           else
Line 73:           {
Line 74:               sqlDataSource.SelectParameters.Clear();
Line 75:               sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
Line 76:               sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
Line 77:               GridView1.DataBind();
Line 78:           }
Line 79:       }
Line 80:   
Line 81:       protected void GridView1_Sorted(object sender, EventArgs e)
Line 82:       {
Line 83:           if (DropDownList1.SelectedValue == "Choose a filter string")
Line 84:           {
Line 85:               GridView1.Visible = true;
Line 86:               GridView1.DataBind();
Line 87:           }
Line 88:           else
Line 89:           {
Line 90:               sqlDataSource.SelectParameters.Clear();
Line 91:               sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
Line 92:               sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
Line 93:               GridView1.DataBind();
Line 94:           }
Line 95:       }
Line 96:       protected void SqlDataSource_Selected(object sender, SqlDataSourceStatusEventArgs e)
Line 97:       {
Line 98:           if (DropDownList1.SelectedValue == "Choose a filter string")
Line 99:           {
Line 100:              LabelCount.Text = "The record count for all records is: " + e.AffectedRows.ToString();
Line 101:          }
Line 102:          else
Line 103:          {
Line 104:              LabelCount.Text = "The record count for " + DropDownList1.SelectedValue + " is: " + e.AffectedRows.ToString();
Line 105:          }
Line 106:  
Line 107:          if (e.Exception != null)
Line 108:          {
Line 109:              LabelCount.Visible = false;
Line 110:              GridView1.EmptyDataText = e.Exception.Message;
Line 111:          }
Line 112:      }
Line 113:  }
 




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3615; ASP.NET Version:2.0.50727.3618 


Anywhere I have a control from the .aspx page, it shows the same error.  This is just the first control reference it encounters.

Will,

I must admit I'm pretty stumped.  Somehow, the .aspx and the code-behind aren't finding each other.

There's one thing I notice about your page that's different from mine.  In the <@Page> directive, you have a "Src=" attribute that my pages never have.  According to this MSDN article:

"You can use the Src attribute to link build providers to the page. For more information, see the BuildProvider class. Also, in versions of ASP.NET prior to 2.0, the Src attribute was used as an alternative way to link a code-behind file to a page. In ASP.NET 2.0, the preferred approach to linking a code-behind source file to a page is to use the Inherits attribute to specify a class, along with the CodeFile attribute to specify the path to the source file for the class."

That's something I've never needed, and I suggest that you try removing it.

I am beginning to this machine has some gremlins.  I use the Src attribute as a workaround to compiler issue.  It was saying it couldn't find the .cs file.  When I added the Src attribute, which I had never used either, it worked fine.  I am positive I have the site set to ASP.NET 2.0 in IIS, so, I don't think it's a version issue.  If I can't get it figured out soon, I might request a different box.  There are all sorts of weird things on this machine that make no sense.  I just wanted to be sure I wasn't overlooking something obvious.

Will,

Did you try taking the Src back out?

Your CodeFile attribute is where you should resolve the "couldn't find the .cs file" issue.  Based on what's in your <@Page> directive, your code must be in a file named "locked_batches.aspx.cs" which must be in the same directory as the .aspx.

Let me know.

 

AHA! I found another possible fix.

The same MSDN page says:

"[CodeFile] is used for Web site projects. The CodeBehind attribute is used for Web application projects."

In other words, if you are creating a Web Application (as opposed to a Web Site) you should change "CodeFile" to "CodeBehind" in your <@Page>.

[RESOLVED] Cache dynamic menu

I'm dynamically creating an asp:menu and asp:treeview (2 separate navigation controls) in my master page based on database entries. What's the best way to prevent these from being re-created every time the user selects a new page (seems like a lot of redundant database calls). Can I somehow cache these objects? Or should I be storing the database values in a session variable which I can re-build from on each new page? Just hoping someone can point me in the right direction.

I recently implemented something similar using cached ArrayLists.  I needed to populate some dropdowns based on DB values and didn't want to make the call over and over again for performance issues:

Custom Class to build out the list: 
ArrayList
returnSizes = new ArrayList();
...some code here to populate the list...
string sizescached = "sizescached" + category + attribute; //Built out a custom name for the cached item based on a category and attribute name
HttpRuntime.Cache.Add(sizescached, returnSizes, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, CacheItemPriority.Default, null); //added it to the cache for 30 minutes at a time

In the page that uses the dropdown:
string sizescached = "sizescached" + curCategory + curAttribute;  //Build out a custom name based on current category and attribute name
ArrayList testCachedSizeList = (ArrayList)Cache[sizescached]; //Pull in the cached arraylist
if (testCachedSizeList == null) //Test the list to see if it has data, if not go pull the list from the custom class

This works like a charm.  This first user to hit the page after the 30 minute time-out experiences a slight delay in page load, but after that its golden.  We used the same technique on our menus as well, and cached them for 8 hour time frames.

Excellent. This looks like just what I was looking for. Thank you!

hi tehremo, thanks your tips. i am just curious. if am not mistaken, even using cache, you still need to create the menu (one by one) on each page right? so, it still need sometime to create the menu especially if the menu has large data.

can we just eliminate the proses to recreating the menu on each page ?

please share..... thanks.......