?
Solved

How do I programmatically assign a value to the Text property in Label control

Posted on 2004-11-30
35
Medium Priority
?
360 Views
Last Modified: 2008-01-09
I am having difficulty assigning a value to the text property in a label control.  The ultimate aim of the page is to pass a value along a query string which will access a SQL Server database and return a page of results using this value as a parameter.  

Page 1 contains a datagrid with three bound columns which display a staff number, surname and forename, and one template column in which I've placed a button which will open a new window, passing the staff code along the query string to Page 2

I'm quite new to ASP.NET so started by playing with Page 2 to see how a label picks up a Text value.  I assigned a simple value to the Text property of the label:

file staff_edit.aspx contains the following:

<p>Staff Code: <asp:label id="Code" runat="server"></asp:label></p>

The code behind this is:

Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Code.Text = "insert staff code here"
End Sub

This is textbook, but doesn't appear to work in my application - what am I doing wrong!!!!

We are also using the Data Application Block for .NET

Any help greatly appreciated :)

0
Comment
Question by:sarahth
  • 15
  • 14
  • 4
  • +2
35 Comments
 
LVL 7

Expert Comment

by:smolam
ID: 12705152
Could you post the ASPX page code for staff_edit.aspx
0
 
LVL 7

Expert Comment

by:smolam
ID: 12705156
Oh and by the way this probably will affect it also but you might want to change the name of the label Code to lblCode because code is an ASP.Net function!
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12705170
what does the Label show, when you load Page 2?

by this code:

Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Code.Text = "insert staff code here"
End Sub


the Label should show

insert staff code here

and you want it to show the ACTAL STAFF CODE from Page 1?

try this:

Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Code.Text = Request.QueryString("StaffCode")
End Sub


assuming that you are getting to Page2 as:

Response.Redirect("Page2.aspx?StaffCode=XXX")

AW
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 35

Expert Comment

by:YZlat
ID: 12705681
it should be working.

try this:

Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     if Not IsPostBack Then
          Code.Text = "insert staff code here"
      end if
End Sub
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12705965
sarah,
  Your problem here is that you have a label control inside of a Datagrid control which means it no longer can be accessed by code.text.  What you need to do is on the datagrids ITEM DATABOUND function add this code:

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound


        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
            Dim code As New Label
            code = e.Item.FindControl("code")
            code.Text = "insert staff code here"
        End If
End Sub

Give this a try!
0
 

Author Comment

by:sarahth
ID: 12706073
Thanks for all your suggestions.

I've tried changing the id of the label to lblCode but that didn't seem to work and using
lblCode = Request.QueryString("staff_code")
doesn't seem to affect anything.

Page 1 (test.aspx) contains the following datagrid:

<asp:datagrid id="DataGrid1" runat="server" AlternatingItemStyle-BorderColor="#ff66ff" AutoGenerateColumns="False" CellPadding="2" CellSpacing="1" BorderColor="White" GridLines="None">

<HeaderStyle Font-Names="Arial" ForeColor="White" BackColor="#000099"></HeaderStyle>
<Columns>
      <asp:TemplateColumn HeaderText="Edit">
      <ItemTemplate>
      <asp:Image id="edit" ImageURL="../images/edit.gif" Runat="server"></asp:Image>
      </ItemTemplate>
      </asp:TemplateColumn>
      <asp:BoundColumn DataField="staff_code" HeaderText="Code"></asp:BoundColumn>
      <asp:BoundColumn DataField="surname" HeaderText="Surname"></asp:BoundColumn>
      <asp:BoundColumn DataField="forename" HeaderText="Forename"></asp:BoundColumn>
</Columns>
</asp:datagrid>

When a user clicks on a button the following will open a new window called staff_edit.aspx in conjunction with a JavaScript in page 1.  This is the code behind page 1:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   
Dim init As String

        If Request.QueryString("initial") = "" Then
            init = ""
        Else
            init = Request.QueryString("initial").ToString()
        End If

        getData(init)
        Session("currClient") = ""
        Session("currClientID") = ""
End Sub

Private Sub getData(ByVal init)

        Dim data As DataSet

        data = SqlHelper.ExecuteDataset(connStr, CommandType.StoredProcedure, "sps_DNS_GetDetails", New SqlClient.SqlParameter("@initial", init))

        DataGrid1.DataSource = data
        DataGrid1.DataBind()

End Sub

Private Sub DataGrid1_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound

        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim edit_button As System.Web.UI.WebControls.Image
            edit_button = e.Item.FindControl("edit")
            edit_button.Attributes.Add("onClick", "ShowWindow('staff_edit.aspx?staff_code=" & DataBinder.Eval(e.Item.DataItem, "staff_code") & "', '400', '400')")
            edit_button.Attributes.Add("onMouseOver", "this.style.cursor='hand'")
            edit_button.Attributes.Add("onMouseOut", "this.style.cursor='normal'")
        End If

End Sub

And here's the JavaScript:

<script language="javascript">
function ShowWindow(file,width,height)
      {
            window.open(file,"opened","status=yes,scrollbars=yes,width=" + width + ",height=" + height);
      }
</script>

Hope this helps top clarify things!
0
 
LVL 7

Expert Comment

by:smolam
ID: 12706108
I know this is silly but is all this included in a <FORM runat=server></FORM> tag?  And is the Grid Binding ok?
0
 

Author Comment

by:sarahth
ID: 12706172
Page 1 seems to be working fine - all snugly in the <form runat="server"></form> tags.  If I take the label out and replace it with static HTML text the new window opens smoothly.

The following error appears when I try getting a value from the Query String and passing it to the label:

Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
0
 
LVL 7

Expert Comment

by:smolam
ID: 12706192
Could you post the codebehind for page 2 please!
0
 

Author Comment

by:sarahth
ID: 12706217
Sure - here it is:

Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data

Public Class staff_edit
    Inherits System.Web.UI.Page
   
#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
        Protected WithEvents lblCode As System.Web.UI.WebControls.Label
   
    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here


        Dim Staff As New Label

        Staff = Request.QueryString("staff_code")

        lblCode.Text = Staff

Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data

Public Class staff_edit
    Inherits System.Web.UI.Page
    'Dim connStr As String = ConfigurationSettings.AppSettings("connection")

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    ' Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Code As System.Web.UI.WebControls.Label
    Protected WithEvents lblCode As System.Web.UI.WebControls.Label
    ' Protected WithEvents staff_code As System.Web.UI.WebControls.Label

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here


        Dim Staff As New Label

        Staff = Request.QueryString("staff_code")

        lblCode.Text = Staff

Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data

Public Class staff_edit
    Inherits System.Web.UI.Page
    'Dim connStr As String = ConfigurationSettings.AppSettings("connection")

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    ' Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Code As System.Web.UI.WebControls.Label
    Protected WithEvents lblCode As System.Web.UI.WebControls.Label
    ' Protected WithEvents staff_code As System.Web.UI.WebControls.Label

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here


        Dim Staff As New Label

        Staff = Request.QueryString("staff_code")

        lblCode.Text = Staff

Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data

Public Class staff_edit
    Inherits System.Web.UI.Page
    'Dim connStr As String = ConfigurationSettings.AppSettings("connection")

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    ' Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Code As System.Web.UI.WebControls.Label
    Protected WithEvents lblCode As System.Web.UI.WebControls.Label
    ' Protected WithEvents staff_code As System.Web.UI.WebControls.Label

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
End Sub

#End Region

Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here


        Dim Staff As String

        Staff = Request.QueryString("staff_code")

        lblCode.Text = Staff


End Sub
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12706221
Sarah if the label is within a datagrid you must do it this way!  the e.item.findcontrol("id of control") will find the control you are looking for within an array such as the datagrid.


Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound


        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
            Dim code As New Label
            code = e.Item.FindControl("code")
            code.Text = "insert staff code here"
        End If
End Sub
0
 

Author Comment

by:sarahth
ID: 12706224
Sorry - seem to have pasted that a few times!
0
 

Author Comment

by:sarahth
ID: 12706267
The label isn't in a data grid - here's the code for the page with the label in it:

<%@ Page Language="vb" Codebehind="staff_edit.aspx.vb" Inherits="comSys.staff_edit"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>staff_edit</title>
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
            <LINK href="../styles.css" type="text/css" rel="StyleSheet">
      </HEAD>
      <body ms_positioning="GridLayout">
            <form runat="server">
                  <P>&nbsp;Edit Staff Details from this window</P>
                  <P></P>
                  <P><asp:label id="lblCode" runat="server"></asp:label></P>
                  <P></P>
            </form>
            <P>&nbsp;</P>
      </body>
</HTML>
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12706335
Sarah I found this error I dont know if this pertains to your problem please review:


  Dim Staff As New Label

        Staff = Request.QueryString("staff_code")

        lblCode.Text = Staff

It shouldnt be a label it should be
 
Dim Staff as string = Request.QueryString("staff_code")
lblcode.text = staff
0
 

Author Comment

by:sarahth
ID: 12706362
Sorry - that was something else I tried before and snuck into my random pasting!

At the moment I'm playing with:
Dim Staff As String

        Staff = Request.QueryString("staff_code")

        lblCode.Text = Staff

0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12706416
Are you still getting the same error if so please post the full error page  Thanks.
0
 

Author Comment

by:sarahth
ID: 12706434
Here's the full error page :)


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

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   comSys.staff_edit.getData(Object staff_code) in H:\nwwRoot\comsys\DNS\staff_edit.aspx.vb:51
   comSys.staff_edit.Page_Load(Object sender, EventArgs e) in H:\nwwRoot\comsys\DNS\staff_edit.aspx.vb:38
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +736

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.910
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12706474
could you paste the code on line 38 on staff_edit.aspx  thanks
0
 

Author Comment

by:sarahth
ID: 12706557
This is where I get confused about how IE reads a .NET file!  staff_edit has only 21 lines!  Here's the complete file

<%@ Page Language="vb" Codebehind="staff_edit.aspx.vb" Inherits="comSys.staff_edit"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>staff_edit</title>
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
            <LINK href="../styles.css" type="text/css" rel="StyleSheet">
      </HEAD>
      <body ms_positioning="GridLayout">
            <form runat="server">
                  <P>&nbsp;Edit Staff Details from this window</P>
                  <P></P>
                  <P><asp:label id="lblCode" runat="server"></asp:label></P>
                  <P></P>
            </form>
            <P>&nbsp;</P>
      </body>
</HTML>



And here's the code behind:

Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data

Public Class staff_edit
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblCode As System.Web.UI.WebControls.Label

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here


        Dim Staff As String = Request.QueryString("staff_code")

        lblCode.Text = Staff

    End Sub


End Class
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12706592
OKay when it says the error line is not from IE its from the .NET Complier but it is referring to the .vb file not the .aspx file
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12706612
OKay since you are unable to assign the string from the querystring to your label just comment those lines out and just try response.write(staff) see if that gives you anything first
0
 

Author Comment

by:sarahth
ID: 12706687
OK - I've now got the following but this still gives me the same error as before:

Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Put user code to initialize the page here


        ' Dim Staff As String = Request.QueryString("staff_code")

        lblCode.Text = "Staff"

    End Sub

0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12706848
Please comment all of the lblcode stuff and just put in this line response.write(Request.QueryString("staff_code")) and make sure this works first before trying to set anything equal to the label
0
 

Author Comment

by:sarahth
ID: 12706999
Ok - that didn't seem to work either :(

COuld this be a server problem - the error message in IE is the same as I was getting previously.  Also when I click File -> View in Browser the error message is different again, referring to a stored procedure that I took out of page when I started to debug:

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

Procedure 'sps_DNS_StaffEdit' expects parameter '@staff_code', which was not supplied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Procedure 'sps_DNS_StaffEdit' expects parameter '@staff_code', which was not supplied.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[SqlException: Procedure 'sps_DNS_StaffEdit' expects parameter '@staff_code', which was not supplied.]
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +45
   System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +5
   System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +38
   Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters)
   Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters)
   comSys.staff_edit.getData(Object staff_code) in H:\nwwRoot\comsys\DNS\staff_edit.aspx.vb:49
   comSys.staff_edit.Page_Load(Object sender, EventArgs e) in H:\nwwRoot\comsys\DNS\staff_edit.aspx.vb:38
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +736

 This stored procedure was designed to take the staff code from the query string and access the database using staff code as a parameter.  
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12707062
alright this seems to be very strange my question is when you are compling this project what page is your start page?  and this second page could you send me the pagename.aspx? with the querystring.  
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12707165
I think what you may be doing is using this page as your start page when you debug but when you do that there is not Querystring value!  Which is giving you these strange errors Please loook into this!
0
 

Author Comment

by:sarahth
ID: 12707255
This is the code for the first page.  This lies within a larger project called comSYS.  When you first load the page you are asked to log on and then you are redirected to test.aspx.  Basically, this page selects a list of staff members from a database, displays their staff code, surname and forename in a datagrid and allows you to open a new window in which you can edit staff details.  This can be filtered by selecting a link from the top of the page i.e. A B C etc


test.aspx
-----------

<%@ Register TagPrefix="uc1" TagName="cMenu" Src="../UI/cMenu.ascx" %>
<%@ Register TagPrefix="uc1" TagName="miuNavButtons" Src="../UI/miuNavButtons.ascx" %>
<%@ Page Language="vb"  Codebehind="Test.aspx.vb" Inherits="comSys.dnsTestPage"%>
<%@ Register TagPrefix="uc1" TagName="tabs" Src="../tabs.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>staffList</title>
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
            <LINK href="../styles.css" type="text/css" rel="StyleSheet">
            <script language="javascript">
            
            function ShowWindow(file,width,height)
                  {
                        window.open(file,"opened","status=yes,scrollbars=yes,width=" + width + ",height=" + height);
                  }
                  
            </script>
      </HEAD>
      <body>
            <form id="Form1" method="post" runat="server">
                  <P></P>
                  <P></P>
                  <P><uc1:tabs id="Tabs1" runat="server"></uc1:tabs></P>
                  <p>Filter Records: <A href="test.aspx?initial=A">A</A>
<A href="test.aspx?initial=B">B</A>
<A href="test.aspx?initial=C">C</A> <A href="test.aspx?initial=D">D</A>
<A href="test.aspx?initial=E">E</A> <A href="test.aspx?initial=F">F</A>
<A href="test.aspx?initial=G">G</A><A href="test.aspx?initial=H">H</A>
<A href="test.aspx?initial=I">I</A> <A href="test.aspx?initial=J">J</A>
<A href="test.aspx?initial=K">K</A> <A href="test.aspx?initial=L">L</A>
<A href="test.aspx?initial=M">M</A> <A href="test.aspx?initial=N">N</A>
<A href="test.aspx?initial=O">O</A> <A href="test.aspx?initial=P">P</A>
<A href="test.aspx?initial=Q">Q</A><A href="test.aspx?initial=R">R</A>
<A href="test.aspx?initial=S">S</A> <A href="test.aspx?initial=T">T</A>
<A href="test.aspx?initial=U">U</A> <A href="test.aspx?initial=V">V</A>
<A href="test.aspx?initial=W">W</A> <A href="test.aspx?initial=X">X</A>
<A href="test.aspx?initial=Y">Y</A> <A href="test.aspx?initial=Z">Z</A></p>
                  <table width="100%">
                        <tbody>
                              <tr>
                                    <td><asp:datagrid id="DataGrid1" runat="server" AlternatingItemStyle-BorderColor="#ff66ff" AutoGenerateColumns="False"
                                                CellPadding="2" CellSpacing="1" BorderColor="White" GridLines="None">
                                                <AlternatingItemStyle BorderColor="#FF66FF"></AlternatingItemStyle>
                                                <HeaderStyle Font-Names="Arial" ForeColor="White" BackColor="#000099"></HeaderStyle>
                                                <Columns>
                                                      <asp:TemplateColumn HeaderText="Edit">
      <ItemTemplate>
      <asp:Image id="edit" ImageURL="../images/edit.gif" Runat="server"></asp:Image>
      </ItemTemplate>
      </asp:TemplateColumn>
      <asp:BoundColumn DataField="staff_code" HeaderText="Code"></asp:BoundColumn>
      <asp:BoundColumn DataField="surname" HeaderText="Surname"></asp:BoundColumn>
      <asp:BoundColumn DataField="forename" HeaderText="Forename"></asp:BoundColumn>
                                                </Columns>
                                          </asp:datagrid></td>
                                    <TD vAlign="top" width="20%"><uc1:cmenu id="Cmenu2" runat="server"></uc1:cmenu></TD>
                              </tr>
                        </tbody>
                  </table>
            </form>
            </FORM></TD></TR></TBODY></TABLE></FORM></body>
</HTML>



The code behind this uses a stored procedure to get the required data from the database and facilitates searching of the first page.


text.aspx.vb
--------------

Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data

Public Class dnsTestPage
    Inherits System.Web.UI.Page
    Dim connStr As String = ConfigurationSettings.AppSettings("connection")

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Categories As System.Web.UI.WebControls.DataGrid
    Protected WithEvents Selection As System.Web.UI.HtmlControls.HtmlSelect
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    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

        Dim init As String

        If Request.QueryString("initial") = "" Then
            init = ""
        Else
            init = Request.QueryString("initial").ToString()
        End If

        getData(init)
        Session("currClient") = ""
        Session("currClientID") = ""
    End Sub

    Private Sub getData(ByVal init)

        Dim data As DataSet

        data = SqlHelper.ExecuteDataset(connStr, CommandType.StoredProcedure, "sps_DNS_GetDetails", New SqlClient.SqlParameter("@initial", init))

        DataGrid1.DataSource = data
        DataGrid1.DataBind()

    End Sub


    Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged

    End Sub

    Private Sub DataGrid1_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound

        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim edit_button As System.Web.UI.WebControls.Image
            edit_button = e.Item.FindControl("edit")
            edit_button.Attributes.Add("onClick", "ShowWindow('staff_edit.aspx?staff_code=" & DataBinder.Eval(e.Item.DataItem, "staff_code") & "', '400', '400')")
            edit_button.Attributes.Add("onMouseOver", "this.style.cursor='hand'")
            edit_button.Attributes.Add("onMouseOut", "this.style.cursor='normal'")
        End If


    End Sub

 
End Class


When the 'edit' button is clicked within the datagrid another window will open displaying staff details.  These will be obtained using a stored procedure which will access the database using staff_code as a parameter.  I don't want to allow users to be able to edit the staff code so I'm using a label.

staff_edit.aspx
-----------------

<%@ Page Language="vb" Codebehind="staff_edit.aspx.vb" Inherits="comSys.staff_edit" trace="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>staff_edit</title>
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
            <LINK href="../styles.css" type="text/css" rel="StyleSheet">
      </HEAD>
      <body ms_positioning="GridLayout">
            <form runat="server">
                  <!-- <P>&nbsp;Edit Staff Details from this window</P>
                  <P></P>
                  <P>Staff Code:
                        <asp:label id="lblCode" runat="server"></asp:label> --> </p>
                  <P><script>Response.Write(Request.QueryString("staff_code"))</script></P>
            </form>
            <P>&nbsp;</P>
      </body>
</HTML>

 The code behind this is :

staff_edit.aspx.vb
--------------------

Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data

Public Class staff_edit
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblCode As System.Web.UI.WebControls.Label

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        'Dim Staff As Integer = Request.QueryString("staff_code")

        'lblCode.Text = Staff

        'Response.Write(Request.QueryString("staff_code"))

    End Sub

End Class


Note - I've commented out varous things as I've been tinkering!

The URL of the staff_edit page is:
staff_edit.aspx?staff_code=32415
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12707428
Okay remove this from your aspx page: <script>Response.Write(Request.QueryString("staff_code"))</script> and just put this line within the page_load event Response.Write(Request.QueryString("staff_code")) and tell me if you get a value.  Once again put this in the .vb file not the aspx page.
0
 

Author Comment

by:sarahth
ID: 12707523
Ok - I'm still getting the following:


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

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   comSys.staff_edit.getData(Object staff_code) in H:\nwwRoot\comsys\DNS\staff_edit.aspx.vb:51
   comSys.staff_edit.Page_Load(Object sender, EventArgs e) in H:\nwwRoot\comsys\DNS\staff_edit.aspx.vb:38
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +736

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.910
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12707587
OKay have you commented out all of the label stuff where you try setting the label.text = something?  Please troubleshoot and find the line of code which is bombing this page.  Once you find it comment it out and get the page to at least run.  Then try the Response.Write(Request.QueryString("staff_code"))
0
 

Author Comment

by:sarahth
ID: 12707615
Everything to do with the label is commented out.  I've now got:

<form runat="server">
<!--<P>&nbsp;Edit Staff Details from this window</P>
<P></P>
<P>Staff Code:<asp:label id="lblCode" runat="server"></asp:label>  </p>-->
                  
</form>

and the code behind is:

Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Put user code to initialize the page here

        ' Dim Staff As Integer = Request.QueryString("staff_code")

        ' lblCode.Text = Staff

        Response.Write(Request.QueryString("staff_code"))

    End Sub
0
 

Author Comment

by:sarahth
ID: 12707641
I'm not sure why, but even with no content this page has problems
0
 
LVL 3

Accepted Solution

by:
gbelken99 earned 450 total points
ID: 12707666
Okay well maybe you should start a new page and just add what is needed.  Apparently something on your page is messed up.  Im sorry this is rather vague but its the best way to solve your issue.
0
 

Author Comment

by:sarahth
ID: 12707703
That's fine - I was beginning to think that rebuilding from scratch would be the answer.  It could be a problem with the included files but I can't change these because the whole project uses these on various pages.

Thanks for taking the time to help me - greatly appreciated.  If I ever find the answer I'll be sure to post it!
0
 
LVL 3

Expert Comment

by:gbelken99
ID: 12707763
I am very sorrry we were unable to find your problem but good luck!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question