Question

ASP.NET and keeping state

Asked by: xloop

Hi there,

I have two dropdown lists that are filled with information from a SQL DB when the page first loads.....  so far so good.

Next from the information the user chooses from the drop down list the page automatically refreshes and gives the user some stats and uses the LinkButton control to display them.

What i would like is for the user to be able to click on a link and the page refresh (with some extra querystring info) while still keeping state with the two drop down lists.

I can do either but i can't seem to work out how to do both.

Thanks in advance.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-03-09 at 00:45:26ID20912048
Tags

dropdown

,

refresh

Topic

.NET

Participating Experts
3
Points
500
Comments
39

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Asp.Net 2.0 LinkButton, Calendar, DropDown
    Can someone tell me if the LinkButton, Calendar, and AutoPostBack of DropDownList in ASP.NET 2.0 works with no JavaScript turned on? I know it didn't work in ASP.Net 1X but not sure if it's been changed or even changeable for 2.0 I haven't downloaded 2.0 yet so can't test i...
  2. dropdown refreshes
    I have datagrid has checkbox , textbox, and dropdown. When checkbox get checked dropdown gets filled from database. ON page load my dropdown is disable, but when it is checked check box it needs to be enable and fiils the dropdown . Everytime this check happens it refreshes ...
  3. ASP.NET Dropdown control refresh
    Codebase: ASP.NET, VB Synopsois: i am creating a contact input screen in which i have a dropdown control called "Contact_Type" if the type the user wants to use is not available in the dropdown control they can push an "Edit" button next to the control to...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: nishikanthPosted on 2004-03-09 at 01:15:40ID: 10548507

make the enable viewstate to true for the controls....

 

by: xloopPosted on 2004-03-09 at 01:17:49ID: 10548520

I am......

BUT if you do a  Response.Redirect("samepage.aspx?stuff=moreinfo",false)   it doesn't actually submit the page again so it cant locate the viewstate information.

 

by: nishikanthPosted on 2004-03-09 at 01:24:23ID: 10548569

why do u need to redirect ....

just in the page load event check the values of two drop down boxes and add additional controls based on the values.

 isPostBack - This is true when the page is posted back again.... check for u r values here and load addl controls here...

not isPostback - means loading for the first time.....

use response.redirect to send the user to another URL.....
Use postback for the same url...

check this
http://www.devx.com/dotnet/Article/10412
http://www.takempis.com/aspnet_fundamentals.asp#How_ASPNet_Maintains_State:
http://www.macromedia.com/devnet/mx/dreamweaver/articles/dotnet_webform_05.html
http://www.dotnetjohn.com/articles/articleid32.aspx



 

by: devplayer04Posted on 2004-03-09 at 01:26:01ID: 10548581

If you wish to keep state across pages, then you alternative is to use the Session Object.
The ViewState Object only maintains state across posts to the same page. Not to the other pages.
Th other thing you might consider is to serialise the ViewState to the database and use it for the other page (advanced level of knowledge)
What you are better off doing is to use a user control in your aspx page, create some public properties and then in a postback, the user control's properties are populated via code, and made visible. Your user control can contain any server controls etc etc,

What you have described is best achieved using UserControls.

 

by: nishikanthPosted on 2004-03-09 at 01:32:14ID: 10548635

Here u don't actuall need to use Session...as it will amke the server relatively slow...

the beauty of asp.net is the postback and maintaining state.... avoid using sessions....

Create the controls selectively on every postback

Or u can also do like this

   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If viewstate("Add") = "True" Then            ''''Check if the drop down list is selectd          
             AddLinkButtondata()
        End If
    End Sub

Private Sub selectbox_selectIndexChanged
      viewstate("Add") = True    ''' Create a viewstate telling that user has selected the drop donw list
    End Sub


pls check the syntax for the SUBRoutines declaration... was impromptu

 

by: xloopPosted on 2004-03-09 at 01:53:43ID: 10548764

devplayer, i only want to maintain state across the same page, BUT i also want to add a querystring to the post.

When the user selects a new value from the dropdown list the page is posted and the new value is retained, this works no problem.
Lets presume i also have a linkbutton which has a value of 5, what i want is to click on the linkbutton for it to submit the page and also the value 5 (to the same page)

How is that done without doing a Response.Redirect

???

 

by: devplayer04Posted on 2004-03-09 at 02:08:15ID: 10548832

you don't need to worry about the querystring,
if a user types in for e.g. http://myserver.com/Page.aspx?id=4

then in the server control form's action attribute, the QueryString is passed thru:
<form action="Page.aspx?id=4" method="post" >

</form>

<%@Page Language="VB"%>
<script language="VB" runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
 If Page.IsPostBack Then
  Dim value As Integer= Convert.ToInt32(LinkButton1.CommandArgument.ToString())
      Literal1.Text = String.Format("<div>Value Is {0}</div>",value) & _
            String.Format("<div>Value Of List Is {0}</div>",CountryList.SelectedItem.Value)
      
 End If
End Sub
</script>
<html>
<head>
<title>Posting Values</title>
</head>
<body>
<form runat="server" ID="Form1">
<asp:DropDownList id="CountryList" runat="server">
<asp:ListItem Value="-1">Please Select</asp:ListItem>
<asp:ListItem Value="7">USA</asp:ListItem>
<asp:ListItem Value="10">UK</asp:ListItem>
</asp:DropDownList>
<asp:LinkButton id="LinkButton1" runat="server" CommandArgument="5">LinkButton</asp:LinkButton>
<asp:Literal id="Literal1" runat="server" />
</form>
</body>
</html>

 

by: xloopPosted on 2004-03-09 at 02:11:12ID: 10548847

right.............so what i then wanted to add another value (as well as the value 5), say  ?report=Schedule

?????

 

by: nishikanthPosted on 2004-03-09 at 02:12:10ID: 10548856


http://www.dotnetjunkies.com/Article/D481E737-BA40-472E-BEBD-E193FC68F8F2.dcik


 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If ViewState("Cat") = True Then
            LoadCategory()
        End If
       If ViewState("Menu") = True Then
            LoadOptionalItem()
        End If
end if

 Private Sub LoadCategory()
        Dim i As Int32
        Dim MenuButton As LinkButton
        For i = 0 To 10
            MenuButton = New LinkButton()
            MenuButton.Width = Unit.Pixel(230)
            MenuButton.CausesValidation = False
            MenuButton.Text = i
            MenuButton.CommandArgument = i
            AddHandler MenuButton.Click, AddressOf Me.LoadMenu
            PlaceHolder.Controls.Add(MenuButton)
        Next
    End Sub

   Private Sub LoadMenu(ByVal sender As System.Object, ByVal e As System.EventArgs)
             response.write(sender.CommandArgument)  '''' this gives the Link button ID
             ViewState("Menu") = True
   End Sub

Private Sub dropdown_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dropdown.SelectedIndexChanged

ViewState("Cat") = True

    End Sub

 

by: nishikanthPosted on 2004-03-09 at 02:13:58ID: 10548868

add multiple viewstates to store the content.....

and change the value of the viewstate

ViewState("query1") = 2
ViewState("query2") = 5

 

by: xloopPosted on 2004-03-09 at 02:16:07ID: 10548884

OK, i think i can use  CommandArgument to store the string, however i now have the problem of when clicking on the LinkButton it refreshes but doesn't seem to save the viewstate information, ie. the dropdown boxes are reset????

 

by: nishikanthPosted on 2004-03-09 at 02:18:12ID: 10548897

it won't reset unless u r dynamically creating the drop down list...

u need to load the controls on every post back... if u dynamically create them... pls see me code above...

 

by: devplayer04Posted on 2004-03-09 at 02:18:59ID: 10548899

<%@Page Language="VB"%>
<script language="VB" runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
 If Page.IsPostBack Then
  Dim args As String = LinkButton1.CommandArgument.ToString()
  Dim values As String () = args.Split(Convert.ToChar("|"))
  Dim id As Integer = Convert.ToInt32(values(0))
  Dim report As String = values(1)

     Literal1.Text = String.Format("<div>Id Is {0}</div><div>Report Is {1}</div>",id,report)
             
 End If
End Sub
</script>
<html>
<head>
<title>Posting Values</title>
</head>
<body>
<form runat="server" ID="Form1">
<asp:DropDownList id="CountryList" runat="server">
<asp:ListItem Value="-1">Please Select</asp:ListItem>
<asp:ListItem Value="7">USA</asp:ListItem>
<asp:ListItem Value="10">UK</asp:ListItem>
</asp:DropDownList>
<asp:LinkButton id="LinkButton1" runat="server" CommandArgument="5|Schedule">LinkButton</asp:LinkButton>
<asp:Literal id="Literal1" runat="server" />
</form>
</body>
</html>

 

by: devplayer04Posted on 2004-03-09 at 02:20:14ID: 10548904

The dropdownlist should not be "refreshed",

Let's see the code.

 

by: xloopPosted on 2004-03-09 at 02:22:24ID: 10548922

This is the code: (all in page load)


string strConn = ConfigurationSettings.AppSettings["ConnString"];
                  Cnn = new SqlConnection(strConn);
                  
                  if (!Page.IsPostBack)
                  {

                        ds = new DataSet();

                        try
                        {
                              Cnn.Open();

                              // fill projects
                              da = new SqlDataAdapter("SELECT tblProjects.ProjectName, tblProjects.ProjectID, tblProjects.ProjectStatusRpt FROM tblCustomerUsers INNER JOIN tblClients ON tblCustomerUsers.ClientID = tblClients.ClientID INNER JOIN tblProjects ON tblClients.ClientID = tblProjects.ClientID WHERE     (tblCustomerUsers.CustomerUsername = '" + User.Identity.Name + "') AND ProjectStatusRpt = 1",Cnn);
                              da.Fill(ds, "Results");
                              lstProject.DataSource = ds.Tables[0].DefaultView;
                              lstProject.DataTextField = "ProjectName";
                              lstProject.DataValueField = "ProjectID";
                              lstProject.DataBind();
                              lstProject.Items.Insert(0,new ListItem("Select project"));

                        }
                        finally
                        {
                              Cnn.Close();
                        }
                  }

                  if (Request["lstProject"] != null)
                  {
                        if (Request["lstProject"].ToString() != "Select project")
                        {
                              //hard code in task name
                              lstTask.Items.Clear();
                              lstTask.Items.Insert(0,new ListItem("Select task"));
                              lstTask.Items.Insert(1,new ListItem("Installation","3"));
                        

                              if (Request["lstTask"] != null)
                              {
                                    if (Request["lstTask"] != "Select task")
                                    {
                                          // we have a task name....
                                          Cnn.Open();
                                          Cmd = new SqlCommand("sp_tm_ProjectStatusRpt " + Request["lstProject"] + "," + Request["lstTask"],Cnn);
                                          SqlDataReader reader = Cmd.ExecuteReader();

                                          while (reader.Read() && Request["lstProject"].ToString() != "Select project")
                                          {
                                                if (reader["Title"].ToString() == "Scheduled Jobs")
                                                {
                                                      lblSchd.Text = reader[1].ToString();
                                                }
                                                else if (reader["Title"].ToString() == "In Progress Jobs")
                                                {
                                                      lblInProgress.Text = reader[1].ToString();
                                                }
                                                else if (reader["Title"].ToString() == "Completed Jobs")
                                                {
                                                      lblCompleted.Text = reader[1].ToString();
                                                }
                                                else if (reader["Title"].ToString() == "Scheduled Jobs Before Today")
                                                {
                                                      lblSchdBeforeToday.Text = reader[1].ToString();
                                                }

                              
                                          }
                                    }
                              }
                        
                        }


                  

                  }

 

by: nishikanthPosted on 2004-03-09 at 02:28:50ID: 10548962

binding of data must be on every post back......


put the bind data code in a separate function and call the function on every post back.....


 

by: devplayer04Posted on 2004-03-09 at 02:35:59ID: 10549010

ah c#, a fellow with good taste!!!
using System.Text;


void Page_Load(object sender, EventArgs e)
{
  string strConn = ConfigurationSettings.AppSettings["ConnString"];
  Cnn = new SqlConnection(strConn);
  if (! Page.IsPostBack)
  {
     ds = new DataSet();
      try
      {
          Cnn.Open();
          StringBuilder sb = new StringBuilder();
          sb.Append("SELECT tblProjects.ProjectName, tblProjects.ProjectID, tblProjects.ProjectStatusRpt FROM tblCustomerUsers ");
          sb.Append("INNER JOIN tblClients ON tblCustomerUsers.ClientID = tblClients.ClientID INNER JOIN tblProjects ON tblClients.ClientID = tblProjects.ClientID ");
          sb.AppendFormat("WHERE tblCustomerUsers.CustomerUsername='{0}' AND ProjectStatusRpt = 1",User.Identity.Name);
          da = new SqlDataAdapter(sb.ToString(),Cnn);
          da.Fill(ds, "Results");
          lstProject.DataSource = ds.Tables[0].DefaultView;
          lstProject.DataTextField = "ProjectName";
          lstProject.DataValueField = "ProjectID";
          lstProject.DataBind();
          lstProject.Items.Insert(0,new ListItem("Select project"));
          }
       finally
       {
             Cnn.Close();
       }
    }
    else if (lstProject.SelectedIndex != 0)
   {
      lstTask.Items.Clear();
      lstTask.Items.Insert(0,new ListItem("Select task"));
      lstTask.Items.Insert(1,new ListItem("Installation","3"));
      /// your code accordingly

    }
}

 

by: xloopPosted on 2004-03-09 at 02:37:03ID: 10549015

Can you write that function for me because i should be able to just comment out the if (!page.ispostback) line and it should work???

 

by: devplayer04Posted on 2004-03-09 at 02:42:28ID: 10549047

amendment
=========
else if (lstProject.SelectedIndex > 0)
{
      lstTask.Items.Clear();
      lstTask.Items.Insert(0,new ListItem("Select task"));
      lstTask.Items.Insert(1,new ListItem("Installation","3"));
      /// your code accordingly

}

next, actually this architecture is not a good idea. becos every post will cause the lstProject to be repopulated whenever
so you have 2 options, either use the SelectedIndexChanged event to autopostback whenever the lstProject is changed or use ViewState:

if (! Page.IsPostBack)
{
  /// initial population
}
else
{
  string value = lstProject.Items.Count == 0 ? String.Empty : lstProject.SelectedItem.Value;
  string persistedValue = ViewState["ProjectId"] == null ? String.Empty : (string)ViewState["ProjectId"];
  if (value.Length == 0)
  {
    /// do whatever to re-initialise the control
    lstTask.Items.Clear();
  }
  else if (value.CompareTo(persistedValue) != 0)
  {
    /// changes have been detected,
    /// re-load the lstTask control
   }
   /// pass in the new value.
   ViewState["ProjectId"] = value;
}




 

by: devplayer04Posted on 2004-03-09 at 02:44:11ID: 10549057

The ViewState is persisted across posts...

 

by: nishikanthPosted on 2004-03-09 at 02:46:17ID: 10549064

check this

http://aspnet.4guysfromrolla.com/demos/dgExample22.aspx

how to load data and bind data


 

by: devplayer04Posted on 2004-03-09 at 02:47:59ID: 10549073

if it is a http get request as in
<a href="Page.aspx?id=2">blah blah blah</a> then no viewstate is persisted because that is not a post.

persistance of viewstate works with postbacks.

 

by: xloopPosted on 2004-03-09 at 02:52:43ID: 10549096

Blimey - can't keep up with you chaps :)

So far i have this which is fine and it does work apart from if i click on the link button it still resets the drop down lists

string strConn = ConfigurationSettings.AppSettings["ConnString"];
                  Cnn = new SqlConnection(strConn);
                  if (! Page.IsPostBack)
                  {
                        ds = new DataSet();
                        try
                        {
                              Cnn.Open();
                              StringBuilder sb = new StringBuilder();
                              sb.Append("SELECT tblProjects.ProjectName, tblProjects.ProjectID, tblProjects.ProjectStatusRpt FROM tblCustomerUsers ");
                              sb.Append("INNER JOIN tblClients ON tblCustomerUsers.ClientID = tblClients.ClientID INNER JOIN tblProjects ON tblClients.ClientID = tblProjects.ClientID ");
                              sb.AppendFormat("WHERE tblCustomerUsers.CustomerUsername='{0}' AND ProjectStatusRpt = 1",User.Identity.Name);
                              da = new SqlDataAdapter(sb.ToString(),Cnn);
                              da.Fill(ds, "Results");
                              lstProject.DataSource = ds.Tables[0].DefaultView;
                              lstProject.DataTextField = "ProjectName";
                              lstProject.DataValueField = "ProjectID";
                              lstProject.DataBind();
                              lstProject.Items.Insert(0,new ListItem("Select project"));
                        }
                        finally
                        {
                              Cnn.Close();
                        }
                  }
                  else if (lstProject.SelectedIndex > 0 && Request["lstTask"] == null)
                  {
                        lstTask.Items.Clear();
                        lstTask.Items.Insert(0,new ListItem("Select task"));
                        lstTask.Items.Insert(1,new ListItem("Installation","3"));
                  
                  }
                  else if (lstTask.SelectedIndex > 0)
                  {
                              // we have a task name....
                              Cnn.Open();
                              Cmd = new SqlCommand("sp_tm_ProjectStatusRpt " + Request["lstProject"] + "," + Request["lstTask"],Cnn);
                              SqlDataReader reader = Cmd.ExecuteReader();

                              while (reader.Read() && Request["lstProject"].ToString() != "Select project")
                              {
                                    if (reader["Title"].ToString() == "Scheduled Jobs")
                                    {
                                          lblSchd.Text = reader[1].ToString();
                                    }
                                    else if (reader["Title"].ToString() == "In Progress Jobs")
                                    {
                                          lblInProgress.Text = reader[1].ToString();
                                    }
                                    else if (reader["Title"].ToString() == "Completed Jobs")
                                    {
                                          lblCompleted.Text = reader[1].ToString();
                                    }
                                    else if (reader["Title"].ToString() == "Scheduled Jobs Before Today")
                                    {
                                          lblSchdBeforeToday.Text = reader[1].ToString();
                                    }
                              

                              
                              }
                        

                  }

 

by: devplayer04Posted on 2004-03-09 at 03:00:54ID: 10549132

give us your aspx page please.

 

by: xloopPosted on 2004-03-09 at 03:05:49ID: 10549164

how would you like it????

It isn't online............        

 

by: xloopPosted on 2004-03-09 at 03:11:00ID: 10549186

Best i can do is post ALL the code..........

Just to let you know i'm currently using HyperLink controls instead of LinkButtons at the moment, set to change if i can get it working...

Here goes

//////////////////////////   HTML

<%@ Page language="c#" Codebehind="ProjectStatusRpt.aspx.cs" AutoEventWireup="false" Inherits="EcsStock.ProjectStatusRpt" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
      <HEAD>
            <title>ProjectStatusRpt</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">
                  <asp:label id="lblStockReport" style="Z-INDEX: 104; LEFT: 15px; POSITION: absolute; TOP: 10px"
                        runat="server" Font-Bold="True" Font-Size="Small" Font-Names="Tahoma" Width="249px">Project Status</asp:label>
                  <asp:Label id="Label8" style="Z-INDEX: 110; LEFT: 10px; POSITION: absolute; TOP: 225px" runat="server"
                        Font-Bold="True" Font-Size="XX-Small" Font-Names="Tahoma" Width="705px" BackColor="Silver"
                        ForeColor="#C00000" Height="5px"></asp:Label>
                  <asp:DropDownList id="lstTask" style="Z-INDEX: 109; LEFT: 450px; POSITION: absolute; TOP: 70px" runat="server"
                        Font-Names="Tahoma" Width="235px" AutoPostBack="True"></asp:DropDownList>
                  <asp:label id="Label7" style="Z-INDEX: 108; LEFT: 400px; POSITION: absolute; TOP: 75px" runat="server"
                        Font-Size="X-Small" Font-Names="Tahoma" Width="50px">Task:</asp:label>
                  <asp:label id="Label3" style="Z-INDEX: 106; LEFT: 15px; POSITION: absolute; TOP: 75px" runat="server"
                        Font-Size="X-Small" Font-Names="Tahoma" Width="50px">Project:</asp:label>
                  <asp:Label id="Label6" style="Z-INDEX: 101; LEFT: 11px; POSITION: absolute; TOP: 38px" runat="server"
                        Font-Bold="True" Font-Size="X-Small" Font-Names="Tahoma" Width="705px" BackColor="Silver"
                        ForeColor="#C00000"></asp:Label>
                  <asp:Button id="btnBack" style="Z-INDEX: 103; LEFT: 563px; POSITION: absolute; TOP: 10px" runat="server"
                        Font-Size="X-Small" Font-Names="Tahoma" CausesValidation="False" Text="Back"></asp:Button>
                  <asp:Button id="btnSignOut" style="Z-INDEX: 102; LEFT: 611px; POSITION: absolute; TOP: 10px"
                        runat="server" Font-Size="X-Small" Font-Names="Tahoma" CausesValidation="False" Text="Sign Out"></asp:Button>
                  <DIV style="BORDER-RIGHT: navy thin solid; BORDER-TOP: navy thin solid; Z-INDEX: 105; LEFT: 10px; BORDER-LEFT: navy thin solid; WIDTH: 705px; BORDER-BOTTOM: navy thin solid; POSITION: absolute; TOP: 105px; HEIGHT: 100px"
                        ms_positioning="GridLayout">
                        <asp:label id="Label5" style="Z-INDEX: 100; LEFT: 100px; POSITION: absolute; TOP: 70px" runat="server"
                              Font-Size="X-Small" Font-Names="Tahoma" Width="100px">Jobs Completed:</asp:label>
                        <asp:label id="Label4" style="Z-INDEX: 101; LEFT: 125px; POSITION: absolute; TOP: 50px" runat="server"
                              Font-Size="X-Small" Font-Names="Tahoma" Width="70px">In Progress:</asp:label>
                        <asp:label id="Label1" style="Z-INDEX: 102; LEFT: 20px; POSITION: absolute; TOP: 30px" runat="server"
                              Font-Size="X-Small" Font-Names="Tahoma" Width="180px">Scheduled Jobs Before Today:</asp:label>
                        <asp:label id="Label2" style="Z-INDEX: 103; LEFT: 100px; POSITION: absolute; TOP: 10px" runat="server"
                              Font-Size="X-Small" Font-Names="Tahoma" Width="95px">Scheduled Jobs:</asp:label>
                        <asp:HyperLink id="lblSchd" style="Z-INDEX: 104; LEFT: 215px; POSITION: absolute; TOP: 10px" runat="server"
                              Font-Bold="True" Font-Size="X-Small" Font-Names="Tahoma" Width="105px" NavigateUrl='" "'></asp:HyperLink>
                        <asp:HyperLink id="lblSchdBeforeToday" style="Z-INDEX: 115; LEFT: 215px; POSITION: absolute; TOP: 30px"
                              runat="server" Font-Bold="True" Font-Size="X-Small" Font-Names="Tahoma" NavigateUrl='" "'></asp:HyperLink>
                        <asp:HyperLink id="lblInProgress" style="Z-INDEX: 115; LEFT: 215px; POSITION: absolute; TOP: 50px"
                              runat="server" Font-Bold="True" Font-Size="X-Small" Font-Names="Tahoma" NavigateUrl='" "'></asp:HyperLink>
                        <asp:HyperLink id="lblCompleted" style="Z-INDEX: 114; LEFT: 215px; POSITION: absolute; TOP: 70px"
                              runat="server" Font-Bold="True" Font-Size="X-Small" Font-Names="Tahoma" NavigateUrl='" "'></asp:HyperLink></DIV>
                  <asp:DropDownList id="lstProject" style="Z-INDEX: 107; LEFT: 75px; POSITION: absolute; TOP: 70px"
                        runat="server" Font-Names="Tahoma" Width="290px" AutoPostBack="True"></asp:DropDownList>
                  <asp:LinkButton id="LinkButton1" style="Z-INDEX: 111; LEFT: 210px; POSITION: absolute; TOP: 255px"
                        runat="server" CommandArgument="scedule report">LinkButton</asp:LinkButton>
                  <asp:Label id="Label9" style="Z-INDEX: 112; LEFT: 245px; POSITION: absolute; TOP: 320px" runat="server">Label</asp:Label>
            </form>
      </body>
</HTML>


////////////////////////   CODE

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;

namespace EcsStock
{
      /// <summary>
      /// Summary description for ProjectStatusRpt.
      /// </summary>
      public class ProjectStatusRpt : System.Web.UI.Page
      {
            protected System.Web.UI.WebControls.Button btnSignOut;
            protected System.Web.UI.WebControls.Button btnBack;
            protected System.Web.UI.WebControls.Label Label6;
            protected System.Web.UI.WebControls.Label Label1;
            protected System.Web.UI.WebControls.Label Label2;
            protected System.Web.UI.WebControls.Label Label4;
            protected System.Web.UI.WebControls.Label Label5;
            protected System.Web.UI.WebControls.Label Label3;
            protected System.Web.UI.WebControls.DropDownList lstProject;
            protected System.Web.UI.WebControls.Label Label7;
            protected System.Web.UI.WebControls.Label lblStockReport;
            protected System.Data.SqlClient.SqlConnection Cnn;
            protected System.Data.SqlClient.SqlCommand Cmd;
            protected System.Data.SqlClient.SqlDataAdapter da;
            protected System.Web.UI.WebControls.DropDownList lstTask;
            protected System.Web.UI.WebControls.Label Label8;
            protected System.Web.UI.WebControls.HyperLink lblCompleted;
            protected System.Web.UI.WebControls.HyperLink lblInProgress;
            protected System.Web.UI.WebControls.HyperLink lblSchdBeforeToday;
            protected System.Web.UI.WebControls.HyperLink lblSchd;
            protected System.Web.UI.WebControls.LinkButton LinkButton1;
            protected System.Web.UI.WebControls.Label Label9;
            protected System.Data.DataSet ds;
      
            private void Page_Load(object sender, System.EventArgs e)
            {
                  
                  string strConn = ConfigurationSettings.AppSettings["ConnString"];
                  Cnn = new SqlConnection(strConn);
                  if (! Page.IsPostBack)
                  {
                        ds = new DataSet();
                        try
                        {
                              Cnn.Open();
                              StringBuilder sb = new StringBuilder();
                              sb.Append("SELECT tblProjects.ProjectName, tblProjects.ProjectID, tblProjects.ProjectStatusRpt FROM tblCustomerUsers ");
                              sb.Append("INNER JOIN tblClients ON tblCustomerUsers.ClientID = tblClients.ClientID INNER JOIN tblProjects ON tblClients.ClientID = tblProjects.ClientID ");
                              sb.AppendFormat("WHERE tblCustomerUsers.CustomerUsername='{0}' AND ProjectStatusRpt = 1",User.Identity.Name);
                              da = new SqlDataAdapter(sb.ToString(),Cnn);
                              da.Fill(ds, "Results");
                              lstProject.DataSource = ds.Tables[0].DefaultView;
                              lstProject.DataTextField = "ProjectName";
                              lstProject.DataValueField = "ProjectID";
                              lstProject.DataBind();
                              lstProject.Items.Insert(0,new ListItem("Select project"));
                        }
                        finally
                        {
                              Cnn.Close();
                        }
                  }
                  else if (lstProject.SelectedIndex > 0 && Request["lstTask"] == null)
                  {
                        lstTask.Items.Clear();
                        lstTask.Items.Insert(0,new ListItem("Select task"));
                        lstTask.Items.Insert(1,new ListItem("Installation","3"));
                  
                  }
                  else if (lstTask.SelectedIndex > 0)
                  {
                              // we have a task name....
                              Cnn.Open();
                              Cmd = new SqlCommand("sp_tm_ProjectStatusRpt " + Request["lstProject"] + "," + Request["lstTask"],Cnn);
                              SqlDataReader reader = Cmd.ExecuteReader();

                              while (reader.Read() && Request["lstProject"].ToString() != "Select project")
                              {
                                    if (reader["Title"].ToString() == "Scheduled Jobs")
                                    {
                                          lblSchd.Text = reader[1].ToString();
                                    }
                                    else if (reader["Title"].ToString() == "In Progress Jobs")
                                    {
                                          lblInProgress.Text = reader[1].ToString();
                                    }
                                    else if (reader["Title"].ToString() == "Completed Jobs")
                                    {
                                          lblCompleted.Text = reader[1].ToString();
                                    }
                                    else if (reader["Title"].ToString() == "Scheduled Jobs Before Today")
                                    {
                                          lblSchdBeforeToday.Text = reader[1].ToString();
                                    }
                              

                              
                              }
                        

                  }


            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.LinkButton1.Click += new System.EventHandler(this.SchdClick);
                  this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            private void SchdClick(object sender, System.EventArgs e)
            {
                  Server.Transfer("ProjectStatusRpt.aspx?blah=lk",true);
                  //Response.Redirect ("ProjectStatusRpt.aspx?blah=lk",false);
            }
      }
}

 

by: devplayer04Posted on 2004-03-09 at 03:18:09ID: 10549216

private void SchdClick(object sender, System.EventArgs e)
{
 // You dont transfer to the same page
 // Server.Transfer("ProjectStatusRpt.aspx?blah=lk",true);
 //Response.Redirect ("ProjectStatusRpt.aspx?blah=lk",false);
}

this calls the SchdClick Remove it
=================
/// this.LinkButton1.Click += new System.EventHandler(this.SchdClick);

 

by: xloopPosted on 2004-03-09 at 03:19:32ID: 10549221

Ah bugger!!!  

Yes that did it...

 

by: xloopPosted on 2004-03-09 at 03:20:14ID: 10549225

I need to eat then i'll come back and give you the points.

 

by: devplayer04Posted on 2004-03-09 at 03:20:37ID: 10549226

Please explain what it is you really want to achieve with your code. Specifically with regard to the parameters. You are doing it the wrong way.

 

by: devplayer04Posted on 2004-03-09 at 03:21:07ID: 10549231

ah hehehehehe

 

by: xloopPosted on 2004-03-09 at 03:37:32ID: 10549314

Right OK.....this what the page does.

User must first select a project from a list, once a project has been selected the user must then select a task, once the task has been selected a query is then ran against the database to return some stats on that task, so various labels (linkbuttons) are filled with numbers (4 linkbuttons i think)

The user can then click on those numbers to view a report (on the same page, which is just a bound datagrid) of what that number actually means.

Now, the report at the bottom of the page will have exactly the same layout but depending on which number you click on will determin the parameters of the query.

That why i want to attach a querystring to each linkbutton so i can say:  samepage.aspx?report=schedule

So when the page is submitted i can pass that value to a stored procedure so it knows what data to return.

Does it make more sense now?

PS. Food was lovely

 

by: devplayer04Posted on 2004-03-09 at 03:58:09ID: 10549386

passing querystring will mean you are reloading the page in which case the viewstate is not being persisted.
you are better off posting to the same page and the page code can pick up the values....

 

by: xloopPosted on 2004-03-09 at 03:59:39ID: 10549391

Well with classic ASP you could pass a querystring AND submit a form at the same time....

nevermind, it works, i think.

Cheers for the help, much appreciated.

 

by: devplayer04Posted on 2004-03-09 at 04:04:51ID: 10549411

in classic ASP, you'd have to rebuild the list items.
in ASP.NET, you do not if you postback and viewstate is enabled.

That is the one of the fundamental difference between classic ASP and ASP.NET
Next, you do not need to pass a querystring in most cases since in Page.Load, you can see at the server-side what is the state of the server controls and decide on what to do etc etc.

All I am saying is to forget about classic ASP (I know it's hard as I myself had to go thru this learning phase) and focus on what ASP.NET actually can do.

All the best!

 

by: xloopPosted on 2004-03-09 at 04:10:19ID: 10549439

Cheers mate - all the help is much appreciated.

PS. You probably wouldn't realise i'm MS Certified in both C# and ASP.NET - was a while ago since i sat the exams though; catch up time.

Thanks again

 

by: nishikanthPosted on 2004-03-09 at 17:22:00ID: 10556721

great guys... in one night there were lot of exchanges ....

 

by: Teknas2004Posted on 2004-03-19 at 19:58:18ID: 10638843

Thanx a lot guys

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...