?
Solved

Session Variable from Datalist

Posted on 2007-08-06
26
Medium Priority
?
427 Views
Last Modified: 2008-02-01
I am a newbie so please bear with me.

I have a datalist that is looking up the item number and revision based on the serial number that I enter in a textbox. How do I store that item number and revision as a session variable so I can use it to compare against the results of another query?

My code looks like this:

<%@ Page Language="VB" EnableSessionState="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %>

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

<script runat="server">

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsPostBack Then
            If Page.IsValid Then
                ToggleOn()
                Me.grdWOinfo.DataSource = Me.srcMaterials()
                Me.grdWOinfo.DataBind()
            End If
        End If
    End Sub
   
    Public Sub ToggleOn()
        Me.lblBcodeColor.Visible = True
        Me.lblBcodeMat.Visible = True
        Me.txtBcodeColor.Visible = True
        Me.txtBcodeMat.Visible = True
        Me.btnVerifyMat.Visible = True
        Me.btnVerifyColor.Visible = True
        'Me.imgLightColor.Visible = True
        'Me.imgLightMat.Visible = True
       
    End Sub
    Public Sub ToggleOff()
        Me.lblBcodeColor.Visible = False
        Me.lblBcodeMat.Visible = False
        Me.txtBcodeColor.Visible = False
        Me.txtBcodeMat.Visible = False
        Me.btnVerifyMat.Visible = False
        Me.btnVerifyColor.Visible = False
        Me.imgLightColor.Visible = True
        Me.imgLightMat.Visible = True
    End Sub

    Protected Sub valWO_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
        If args.Value.Length = 7 And IsNumeric(args.Value) Then
            args.IsValid = True
        Else
            args.IsValid = False
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.lblDate.Text = Now.ToString
        Session("matitem") = "Hello"
        Me.Label1.Text = Session("matitem").ToString
    End Sub

    Protected Sub btnVerifyMat_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.DataList1.DataSource = Me.srcLbl_Mat
        Me.DataList1.DataBind()
        Dim dvMat As DataView = CType(Me.srcLbl_Mat.Select(DataSourceSelectArguments.Empty), DataView)
        Dim drMat As DataRow = dvMat.Table.Rows(0)
        Session("matitem") = drMat("itemno").ToString() & drMat("rev").ToString()
       
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CPI Work Order Materials Verification</title>
    <style>
    body{margin: 0; padding: 0; font: arial; font-size: 12px;}
    #screen{width: 320px; height 320px; border: 1px solid #000;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="screen">
        <asp:Label ID="lblInitials" runat="server" Text="Initials"></asp:Label><asp:TextBox ID="txtInitials" runat="server" Columns="4" MaxLength="4" ValidationGroup="Validate_WO"></asp:TextBox>
        <asp:RequiredFieldValidator ID="valInitials" runat="server" ErrorMessage="Please enter initials" ControlToValidate="txtInitials" SetFocusOnError="True" ValidationGroup="Validate_WO"></asp:RequiredFieldValidator>&nbsp;
        <asp:Label ID="lblDate" runat="server"></asp:Label><br />
        <asp:Label ID="lblWO" runat="server" Text="W/O #:"></asp:Label><asp:TextBox ID="txtWO" runat="server" MaxLength="7" Columns="7" Font-Size="12px" ValidationGroup="Validate_WO"></asp:TextBox>
        <asp:Button ID="btnLookupWO" runat="server" Text="Lookup W/O" Font-Size="12px" ValidationGroup="Validate_WO" />
        <asp:CustomValidator ID="valWO" runat="server" ControlToValidate="txtWO" ErrorMessage="Workorder is not valid"
            SetFocusOnError="True" ValidateEmptyText="True" OnServerValidate="valWO_ServerValidate" ValidationGroup="Validate_WO"></asp:CustomValidator><br />
        <asp:GridView ID="grdWOinfo" runat="server" Height="22px">
        </asp:GridView>
        <br />
        <asp:Label ID="lblBcodeMat" runat="server" Text="Material Barcode:" Visible="False"></asp:Label>
        <asp:TextBox ID="txtBcodeMat" runat="server" Font-Size="12px" Visible="False" Columns="12" MaxLength="12" ></asp:TextBox>&nbsp;
        <asp:Button ID="btnVerifyMat" runat="server" Text="Verify Material" Font-Size="12px" Visible="False" OnClick="btnVerifyMat_Click" /><br />
        <asp:Image
            ID="imgLightMat" runat="server" ImageUrl="http://intranet.cpi.com/_i/light_y.jpg" Visible="False" />
        <asp:DataList ID="DataList1" runat="server">
            <ItemTemplate>
                Itemno: <%#Eval("Itemno") %><%# Eval("Rev") %>
            </ItemTemplate>
        </asp:DataList><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:Label ID="lblBcodeColor" runat="server" Text="Colorant Barcode:" Visible="False" ></asp:Label>
        <asp:TextBox ID="txtBcodeColor" runat="server" Visible="False" Font-Size="12px" Columns="12" MaxLength="12" ></asp:TextBox>&nbsp;
        <asp:Button ID="btnVerifyColor" runat="server" Text="Verify Colorant" Font-Size="12px" Visible="False" /><br />
        <asp:Image
            ID="imgLightColor" runat="server" ImageUrl="http://intranet.cpi.com/_i/light_y.png" Visible="False" /><br />
        <asp:Label ID="lblColorItemNo" runat="server" Text=""></asp:Label>&nbsp;
        <asp:FormView ID="fvwColorant" runat="server" Width="316px" >
            <EditItemTemplate>
                ITEMNO:
                <asp:TextBox ID="ITEMNOTextBox" runat="server" Text='<%# Bind("ITEMNO") %>'>
                </asp:TextBox><br />
                REV:
                <asp:TextBox ID="REVTextBox" runat="server" Text='<%# Bind("REV") %>'>
                </asp:TextBox><br />
                SERIAL:
                <asp:TextBox ID="SERIALTextBox" runat="server" Text='<%# Bind("SERIAL") %>'>
                </asp:TextBox><br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                    Text="Update">
                </asp:LinkButton>
                <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel">
                </asp:LinkButton>
            </EditItemTemplate>
            <InsertItemTemplate>
                ITEMNO:
                <asp:TextBox ID="ITEMNOTextBox" runat="server" Text='<%# Bind("ITEMNO") %>'>
                </asp:TextBox><br />
                REV:
                <asp:TextBox ID="REVTextBox" runat="server" Text='<%# Bind("REV") %>'>
                </asp:TextBox><br />
                SERIAL:
                <asp:TextBox ID="SERIALTextBox" runat="server" Text='<%# Bind("SERIAL") %>'>
                </asp:TextBox><br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                    Text="Insert">
                </asp:LinkButton>
                <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel">
                </asp:LinkButton>
            </InsertItemTemplate>
            <ItemTemplate>
                ITEMNO:
                <asp:Label ID="ITEMNOLabel" runat="server" Text='<%# Bind("ITEMNO") %>'></asp:Label>
                REV:
                <asp:Label ID="REVLabel" runat="server" Text='<%# Bind("REV") %>'></asp:Label><asp:Label ID="SERIALLabel" runat="server" Text='<%# Bind("SERIAL") %>' Visible="False"></asp:Label>
            </ItemTemplate>
        </asp:FormView>
        <asp:SqlDataSource ID="srcMaterials" runat="server" ConnectionString="<%$ ConnectionStrings:conIqora %>"
            ProviderName="<%$ ConnectionStrings:conIqora.ProviderName %>"
            SelectCommand="SELECT V_SCHED.WORKORDER_ID AS WO, STANDARD.MFGNO, TRIM(ARINVT_MAT.ITEMNO) || '' || TRIM(ARINVT_MAT.REV) AS MATNO, TRIM(ARINVT_COLOR.ITEMNO) || '' || TRIM(ARINVT_COLOR.REV) AS COLORNO, ARINVT_MAT.ID AS MID, ARINVT_COLOR.ID AS CID FROM V_SCHED V_SCHED, STANDARD STANDARD, ARINVT ARINVT_MAT, PARTNO PARTNO, PTOPER PTOPER, OPMAT OPMAT, ARINVT ARINVT_COLOR WHERE V_SCHED.STANDARD_ID = STANDARD.ID (+) AND STANDARD.ARINVT_ID_MAT = ARINVT_MAT.ID (+) AND STANDARD.ID = PARTNO.STANDARD_ID (+) AND PARTNO.ID = PTOPER.PARTNO_ID (+) AND PTOPER.SNDOP_ID = OPMAT.SNDOP_ID (+) AND OPMAT.ARINVT_ID = ARINVT_COLOR.ID (+) AND (ARINVT_COLOR.CLASS (+) = 'CL') AND (OPMAT.SEQ (+) = 1) AND (ROWNUM = 1)" filterexpression="WO = '{0}'">
            <FilterParameters>
                <asp:ControlParameter ControlID="txtWO" Name="newparameter" PropertyName="Text" />
            </FilterParameters>

        </asp:SqlDataSource>
        <br />
        <asp:SqlDataSource ID="srcLbl_Mat" runat="server" ConnectionString="<%$ ConnectionStrings:conIqora %>" ProviderName="<%$ ConnectionStrings:conIqora.ProviderName %>" SelectCommand="SELECT ITEMNO, REV, SERIAL FROM MASTER_LABEL WHERE CLASS IN ('PL','RG')" FilterExpression="SERIAL = '{0}'">
            <FilterParameters>
                <asp:ControlParameter ControlID="txtBcodeMat" Name="newparameter" PropertyName="Text" />
            </FilterParameters>
        </asp:SqlDataSource>
       
    </div>
    </form>
</body>
</html>
0
Comment
Question by:bhorlings
  • 14
  • 12
26 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19639906
Are you talking about this line?

Session("matitem") = drMat("itemno").ToString() & drMat("rev").ToString()


Bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19640432
Yes. I want to store that as a session variable and then I still need to add another session variable for my query that involves the workorder. I will compare those two session variables and if they match it will say it's good and if not it will say it is bad ( I still have to program that part).
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19640513
I am confused.  What is your question?  How can I help?

Bob
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:bhorlings
ID: 19640595
I want to store a session variable for this datalist and then put it into the label1. Does that make more sense?

<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
Itemno: <%#Eval("Itemno") %><%# Eval("Rev") %>
</ItemTemplate>
</asp:DataList>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19640654
Not really.  Are you saying that you want to put the DataSource for the DataList into a session variable?  How many items will the DataList have?

Bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19640671
It will return one row with two columns (Itemno, Rev)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19640714
Try this:

Dim itemNo As String = CType(Me.DataList1.Items(0).DataItem, DataRowView)("Itemno")

Dim rev As String = CType(Me.DataList1.Items(0).DataItem, DataRowView)("Rev")

Session("currentItem") = itemNo & rev

Bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19640722
Where do i put that? In the button click after I bind the data? Then I should be able to place it into the label in the page load correct? Sorry... This is all new to me.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19640761
This is where you tell me where you want it.  What other query to you want to compare these values against?

Bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19640776
I want to compare it to matno from the srcMaterials SqlDataSource.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19640791
Yes, but describe in words what the process needs to be for the comparison.

Example:
1) Get data
2) Bind to DataList
3) Select item
4) Click button
5) Get query results and compare to initial item.

Bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19640852
Okay... Here is the process of everything I want this page to accomplish.

1. Page Loads
2. User enters initials
3. User enters workorder
4. User clicks on btnLookupWO
5. Databinds from srcMaterials
6. Session variable stored for matno from srcMaterials
7. DataView Displays
8. Materials & Colorant Fields become visible
9. User enters serial number for material
10. User clicks btnMatLookup
11. Bind to Datalist
12. Session variable for currentItem
13. Display currentItem in label1
14. Compare currentItem to matno display error message if it does not equal the matno from workorder
I need to then repeat the process of steps 9-14 for the colorant and colorno

Does that make sense?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19640859
Perfect!!

Where does step #5 occur?

Bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19640922
That happens when the user click on btnLookupWO

Thanks for the help too.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19641149
I don't see an event handler for 'btnLookupWO', so you would need to add one, and get the values from the DataList there.

bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19641217
Okay.. Here is what I have now.

<%@ Page Language="VB" EnableSessionState="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %>

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

<script runat="server">

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsPostBack Then
            If Page.IsValid Then
                ToggleOn()
                Me.grdWOinfo.DataSource = Me.srcMaterials()
                Me.grdWOinfo.DataBind()
            End If
        End If
    End Sub
   
    Public Sub ToggleOn()
        Me.lblBcodeColor.Visible = True
        Me.lblBcodeMat.Visible = True
        Me.txtBcodeColor.Visible = True
        Me.txtBcodeMat.Visible = True
        Me.btnVerifyMat.Visible = True
        Me.btnVerifyColor.Visible = True
        'Me.imgLightColor.Visible = True
        'Me.imgLightMat.Visible = True
       
    End Sub
    Public Sub ToggleOff()
        Me.lblBcodeColor.Visible = False
        Me.lblBcodeMat.Visible = False
        Me.txtBcodeColor.Visible = False
        Me.txtBcodeMat.Visible = False
        Me.btnVerifyMat.Visible = False
        Me.btnVerifyColor.Visible = False
        ' Me.imgLightColor.Visible = True
        Me.imgLightMat.Visible = True
    End Sub

    Protected Sub valWO_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
        If args.Value.Length = 7 And IsNumeric(args.Value) Then
            args.IsValid = True
        Else
            args.IsValid = False
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.lblDate.Text = Now.ToString
        'Me.Label1.Text = Session("matitem").ToString
        Me.Label2.Text = Session("currentItem").ToString
    End Sub

    Protected Sub btnVerifyMat_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.DataList1.DataSource = Me.srcLbl_Mat
        Me.DataList1.DataBind()
        Dim itemNo As String = CType(Me.DataList1.Items(0).DataItem, DataRowView)("Itemno")
        Dim rev As String = CType(Me.DataList1.Items(0).DataItem, DataRowView)("Rev")
        Session("currentItem") = itemNo & rev
    End Sub

    Protected Sub btnLookupWO_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CPI Work Order Materials Verification</title>
    <style>
    body{margin: 0; padding: 0; font: arial; font-size: 12px;}
    #screen{width: 320px; height 320px; border: 1px solid #000;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="screen">
        <asp:Label ID="lblInitials" runat="server" Text="Initials"></asp:Label><asp:TextBox ID="txtInitials" runat="server" Columns="4" MaxLength="4" ValidationGroup="Validate_WO"></asp:TextBox>
        <asp:RequiredFieldValidator ID="valInitials" runat="server" ErrorMessage="Please enter initials" ControlToValidate="txtInitials" SetFocusOnError="True" ValidationGroup="Validate_WO"></asp:RequiredFieldValidator>&nbsp;
        <asp:Label ID="lblDate" runat="server"></asp:Label><br />
        <asp:Label ID="lblWO" runat="server" Text="W/O #:"></asp:Label><asp:TextBox ID="txtWO" runat="server" MaxLength="7" Columns="7" Font-Size="12px" ValidationGroup="Validate_WO"></asp:TextBox>
        <asp:Button ID="btnLookupWO" runat="server" Text="Lookup W/O" Font-Size="12px" ValidationGroup="Validate_WO" OnClick="btnLookupWO_Click" />
        <asp:CustomValidator ID="valWO" runat="server" ControlToValidate="txtWO" ErrorMessage="Workorder is not valid"
            SetFocusOnError="True" ValidateEmptyText="True" OnServerValidate="valWO_ServerValidate" ValidationGroup="Validate_WO"></asp:CustomValidator><br />
        <asp:GridView ID="grdWOinfo" runat="server" Height="22px">
        </asp:GridView>
        <br />
        <asp:Label ID="lblBcodeMat" runat="server" Text="Material Barcode:" Visible="False"></asp:Label>
        <asp:TextBox ID="txtBcodeMat" runat="server" Font-Size="12px" Visible="False" Columns="12" MaxLength="12" ></asp:TextBox>&nbsp;
        <asp:Button ID="btnVerifyMat" runat="server" Text="Verify Material" Font-Size="12px" Visible="False" OnClick="btnVerifyMat_Click" /><br />
        <asp:Image
            ID="imgLightMat" runat="server" ImageUrl="http://intranet.cpi.com/_i/light_y.jpg" Visible="False" />
        <asp:DataList ID="DataList1" runat="server">
            <ItemTemplate>
                Itemno: <%#Eval("Itemno") %><%# Eval("Rev") %>
            </ItemTemplate>
        </asp:DataList>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
        <asp:Label ID="lblBcodeColor" runat="server" Text="Colorant Barcode:" Visible="False" ></asp:Label>
        <asp:TextBox ID="txtBcodeColor" runat="server" Visible="False" Font-Size="12px" Columns="12" MaxLength="12" ></asp:TextBox>&nbsp;
        <asp:Button ID="btnVerifyColor" runat="server" Text="Verify Colorant" Font-Size="12px" Visible="False" /><br />
        <br />
        &nbsp;&nbsp;
        <asp:SqlDataSource ID="srcMaterials" runat="server" ConnectionString="<%$ ConnectionStrings:conIqora %>"
            ProviderName="<%$ ConnectionStrings:conIqora.ProviderName %>"
            SelectCommand="SELECT V_SCHED.WORKORDER_ID AS WO, STANDARD.MFGNO, TRIM(ARINVT_MAT.ITEMNO) || '' || TRIM(ARINVT_MAT.REV) AS MATNO, TRIM(ARINVT_COLOR.ITEMNO) || '' || TRIM(ARINVT_COLOR.REV) AS COLORNO FROM V_SCHED V_SCHED, STANDARD STANDARD, ARINVT ARINVT_MAT, PARTNO PARTNO, PTOPER PTOPER, OPMAT OPMAT, ARINVT ARINVT_COLOR WHERE V_SCHED.STANDARD_ID = STANDARD.ID (+) AND STANDARD.ARINVT_ID_MAT = ARINVT_MAT.ID (+) AND STANDARD.ID = PARTNO.STANDARD_ID (+) AND PARTNO.ID = PTOPER.PARTNO_ID (+) AND PTOPER.SNDOP_ID = OPMAT.SNDOP_ID (+) AND OPMAT.ARINVT_ID = ARINVT_COLOR.ID (+) AND (ARINVT_COLOR.CLASS (+) = 'CL') AND (OPMAT.SEQ (+) = 1)" filterexpression="WO = '{0}'">
            <FilterParameters>
                <asp:ControlParameter ControlID="txtWO" Name="newparameter" PropertyName="Text" />
            </FilterParameters>
            <SelectParameters>
                <asp:SessionParameter Name="woMatNo" SessionField="MATNO" />
                <asp:SessionParameter Name="woColorNo" SessionField="COLORNO" />
            </SelectParameters>

        </asp:SqlDataSource>
        <br />
        <asp:SqlDataSource ID="srcLbl_Mat" runat="server" ConnectionString="<%$ ConnectionStrings:conIqora %>" ProviderName="<%$ ConnectionStrings:conIqora.ProviderName %>" SelectCommand="SELECT ITEMNO, REV, SERIAL FROM MASTER_LABEL WHERE CLASS IN ('PL','RG')" FilterExpression="SERIAL = '{0}'">
            <FilterParameters>
                <asp:ControlParameter ControlID="txtBcodeMat" Name="newparameter" PropertyName="Text" />
            </FilterParameters>
            <SelectParameters>
                <asp:SessionParameter Name="matitem" SessionField="ITEMNO" />
                <asp:SessionParameter Name="matrev" SessionField="REV" />
            </SelectParameters>
        </asp:SqlDataSource>
       
    </div>
    </form>
</body>
</html>

I get an "object is not set to a reference" error message  on the line with in the Page_Load section

Me.Label2.Text = Session("currentItem").ToString
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19641241
1) You are not checking for Page.IsPostBack, so the initial time the session variable wouldn't have been set.

2) If you are setting the session variable in a button click handler, then you should set the label to that value in the same place.

3) Here is an abbreviated order of things:

Page_Load
Page_PreRender
Button_Click

4) As you can see the value for session variable couldn't be visible from Page_Load, since it is set after.

Bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19641308
Okay... I made the changes and get this error Object reference not set to an instance of an object. on this line in the btnVerifyMat_Click. Thanks again for your help. Below is my code.

<%@ Page Language="VB" EnableSessionState="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %>

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

<script runat="server">

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsPostBack Then
            If Page.IsValid Then
                ToggleOn()
                Me.grdWOinfo.DataSource = Me.srcMaterials()
                Me.grdWOinfo.DataBind()
            End If
        End If
    End Sub
   
    Public Sub ToggleOn()
        Me.lblBcodeColor.Visible = True
        Me.lblBcodeMat.Visible = True
        Me.txtBcodeColor.Visible = True
        Me.txtBcodeMat.Visible = True
        Me.btnVerifyMat.Visible = True
        Me.btnVerifyColor.Visible = True
        'Me.imgLightColor.Visible = True
        'Me.imgLightMat.Visible = True
       
    End Sub
    Public Sub ToggleOff()
        Me.lblBcodeColor.Visible = False
        Me.lblBcodeMat.Visible = False
        Me.txtBcodeColor.Visible = False
        Me.txtBcodeMat.Visible = False
        Me.btnVerifyMat.Visible = False
        Me.btnVerifyColor.Visible = False
        ' Me.imgLightColor.Visible = True
        Me.imgLightMat.Visible = True
    End Sub

    Protected Sub valWO_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
        If args.Value.Length = 7 And IsNumeric(args.Value) Then
            args.IsValid = True
        Else
            args.IsValid = False
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.lblDate.Text = Now.ToString
        If Page.IsPostBack Then
           
        End If
        'Me.Label1.Text = Session("matitem").ToString
       
    End Sub

    Protected Sub btnVerifyMat_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.DataList1.DataSource = Me.srcLbl_Mat
        Me.DataList1.DataBind()
        Dim itemNo As String = CType(Me.DataList1.Items(0).DataItem, DataRowView)("Itemno")
        Dim rev As String = CType(Me.DataList1.Items(0).DataItem, DataRowView)("Rev")
        Session("currentItem") = itemNo & rev
        Me.Label2.Text = Session("currentItem").ToString
    End Sub

    Protected Sub btnLookupWO_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CPI Work Order Materials Verification</title>
    <style>
    body{margin: 0; padding: 0; font: arial; font-size: 12px;}
    #screen{width: 320px; height 320px; border: 1px solid #000;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="screen">
        <asp:Label ID="lblInitials" runat="server" Text="Initials"></asp:Label><asp:TextBox ID="txtInitials" runat="server" Columns="4" MaxLength="4" ValidationGroup="Validate_WO"></asp:TextBox>
        <asp:RequiredFieldValidator ID="valInitials" runat="server" ErrorMessage="Please enter initials" ControlToValidate="txtInitials" SetFocusOnError="True" ValidationGroup="Validate_WO"></asp:RequiredFieldValidator>&nbsp;
        <asp:Label ID="lblDate" runat="server"></asp:Label><br />
        <asp:Label ID="lblWO" runat="server" Text="W/O #:"></asp:Label><asp:TextBox ID="txtWO" runat="server" MaxLength="7" Columns="7" Font-Size="12px" ValidationGroup="Validate_WO"></asp:TextBox>
        <asp:Button ID="btnLookupWO" runat="server" Text="Lookup W/O" Font-Size="12px" ValidationGroup="Validate_WO" OnClick="btnLookupWO_Click" />
        <asp:CustomValidator ID="valWO" runat="server" ControlToValidate="txtWO" ErrorMessage="Workorder is not valid"
            SetFocusOnError="True" ValidateEmptyText="True" OnServerValidate="valWO_ServerValidate" ValidationGroup="Validate_WO"></asp:CustomValidator><br />
        <asp:GridView ID="grdWOinfo" runat="server" Height="22px">
        </asp:GridView>
        <br />
        <asp:Label ID="lblBcodeMat" runat="server" Text="Material Barcode:" Visible="False"></asp:Label>
        <asp:TextBox ID="txtBcodeMat" runat="server" Font-Size="12px" Visible="False" Columns="12" MaxLength="12" ></asp:TextBox>&nbsp;
        <asp:Button ID="btnVerifyMat" runat="server" Text="Verify Material" Font-Size="12px" Visible="False" OnClick="btnVerifyMat_Click" /><br />
        <asp:Image
            ID="imgLightMat" runat="server" ImageUrl="http://intranet.cpi.com/_i/light_y.jpg" Visible="False" />
        <asp:DataList ID="DataList1" runat="server">
            <ItemTemplate>
                Itemno: <%#Eval("Itemno") %><%# Eval("Rev") %>
            </ItemTemplate>
        </asp:DataList>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
        <asp:Label ID="lblBcodeColor" runat="server" Text="Colorant Barcode:" Visible="False" ></asp:Label>
        <asp:TextBox ID="txtBcodeColor" runat="server" Visible="False" Font-Size="12px" Columns="12" MaxLength="12" ></asp:TextBox>&nbsp;
        <asp:Button ID="btnVerifyColor" runat="server" Text="Verify Colorant" Font-Size="12px" Visible="False" /><br />
        <br />
        &nbsp;&nbsp;
        <asp:SqlDataSource ID="srcMaterials" runat="server" ConnectionString="<%$ ConnectionStrings:conIqora %>"
            ProviderName="<%$ ConnectionStrings:conIqora.ProviderName %>"
            SelectCommand="SELECT V_SCHED.WORKORDER_ID AS WO, STANDARD.MFGNO, TRIM(ARINVT_MAT.ITEMNO) || '' || TRIM(ARINVT_MAT.REV) AS MATNO, TRIM(ARINVT_COLOR.ITEMNO) || '' || TRIM(ARINVT_COLOR.REV) AS COLORNO FROM V_SCHED V_SCHED, STANDARD STANDARD, ARINVT ARINVT_MAT, PARTNO PARTNO, PTOPER PTOPER, OPMAT OPMAT, ARINVT ARINVT_COLOR WHERE V_SCHED.STANDARD_ID = STANDARD.ID (+) AND STANDARD.ARINVT_ID_MAT = ARINVT_MAT.ID (+) AND STANDARD.ID = PARTNO.STANDARD_ID (+) AND PARTNO.ID = PTOPER.PARTNO_ID (+) AND PTOPER.SNDOP_ID = OPMAT.SNDOP_ID (+) AND OPMAT.ARINVT_ID = ARINVT_COLOR.ID (+) AND (ARINVT_COLOR.CLASS (+) = 'CL') AND (OPMAT.SEQ (+) = 1)" filterexpression="WO = '{0}'">
            <FilterParameters>
                <asp:ControlParameter ControlID="txtWO" Name="newparameter" PropertyName="Text" />
            </FilterParameters>

        </asp:SqlDataSource>
        <br />
        <asp:SqlDataSource ID="srcLbl_Mat" runat="server" ConnectionString="<%$ ConnectionStrings:conIqora %>" ProviderName="<%$ ConnectionStrings:conIqora.ProviderName %>" SelectCommand="SELECT ITEMNO, REV, SERIAL FROM MASTER_LABEL WHERE CLASS IN ('PL','RG')" FilterExpression="SERIAL = '{0}'">
            <FilterParameters>
                <asp:ControlParameter ControlID="txtBcodeMat" Name="newparameter" PropertyName="Text" />
            </FilterParameters>
        </asp:SqlDataSource>
       
    </div>
    </form>
</body>
</html>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19642986
On which line?

Bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19644888
Dim itemNo As String = CType(Me.DataList1.Items(0).DataItem, DataRowView)("Itemno")

It is the third line inside the btnVerifyMat_Click
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19645833
Try changing this:

 Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsPostBack Then
            If Page.IsValid Then
                ToggleOn()
                Me.grdWOinfo.DataSource = Me.srcMaterials()
                Me.grdWOinfo.DataBind()
            End If
        End If
    End Sub

to this:

       Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsPostBack Then
            If Page.IsValid Then
                ToggleOn()
                Me.grdWOinfo.DataSource = Me.srcMaterials()
                Me.grdWOinfo.DataBind()
            End If
        End If
    End Sub
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19645843
Looking here:

The ASP.NET Page Life Cycle
http://www.15seconds.com/issue/020102.htm

the modified order for the events is:

Page_Load
Button_Click
Page_PreRender

Bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19646575
I had to put the
        If Page.IsValid Then
            ToggleOn()
            Me.grdWOinfo.DataSource = Me.srcMaterials()
            Me.grdWOinfo.DataBind()
        End If
in the btnLookupWO_blick event handler.
Here is my code now.

<%@ Page Language="VB" EnableSessionState="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %>

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

<script runat="server">

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
   
    Public Sub ToggleOn()
        Me.lblBcodeColor.Visible = True
        Me.lblBcodeMat.Visible = True
        Me.txtBcodeColor.Visible = True
        Me.txtBcodeMat.Visible = True
        Me.btnVerifyMat.Visible = True
        Me.btnVerifyColor.Visible = True
        'Me.imgLightColor.Visible = True
        'Me.imgLightMat.Visible = True
       
    End Sub
    Public Sub ToggleOff()
        Me.lblBcodeColor.Visible = False
        Me.lblBcodeMat.Visible = False
        Me.txtBcodeColor.Visible = False
        Me.txtBcodeMat.Visible = False
        Me.btnVerifyMat.Visible = False
        Me.btnVerifyColor.Visible = False
        ' Me.imgLightColor.Visible = True
        Me.imgLightMat.Visible = True
    End Sub

    Protected Sub valWO_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
        If args.Value.Length = 7 And IsNumeric(args.Value) Then
            args.IsValid = True
        Else
            args.IsValid = False
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.lblDate.Text = Now.ToString
        'Me.Label1.Text = Session("matitem").ToString
       
    End Sub

    Protected Sub btnVerifyMat_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.DataList1.DataSource = Me.srcLbl_Mat
        Me.DataList1.DataBind()
        Dim itemNo As String = CType(Me.DataList1.Items(0).DataItem, DataRowView)("Itemno")
        Dim rev As String = CType(Me.DataList1.Items(0).DataItem, DataRowView)("Rev")
        Session("currentItem") = itemNo & rev
        Me.Label1.Text = Session("currentItem").ToString
    End Sub

    Protected Sub btnLookupWO_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsValid Then
            ToggleOn()
            Me.grdWOinfo.DataSource = Me.srcMaterials()
            Me.grdWOinfo.DataBind()
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CPI Work Order Materials Verification</title>
    <style>
    body{margin: 0; padding: 0; font: arial; font-size: 12px;}
    #screen{width: 320px; height 320px; border: 1px solid #000;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="screen">
        <asp:Label ID="lblInitials" runat="server" Text="Initials"></asp:Label><asp:TextBox ID="txtInitials" runat="server" Columns="4" MaxLength="4" ValidationGroup="Validate_WO"></asp:TextBox>
        <asp:RequiredFieldValidator ID="valInitials" runat="server" ErrorMessage="Please enter initials" ControlToValidate="txtInitials" SetFocusOnError="True" ValidationGroup="Validate_WO"></asp:RequiredFieldValidator>&nbsp;
        <asp:Label ID="lblDate" runat="server"></asp:Label><br />
        <asp:Label ID="lblWO" runat="server" Text="W/O #:"></asp:Label><asp:TextBox ID="txtWO" runat="server" MaxLength="7" Columns="7" Font-Size="12px" ValidationGroup="Validate_WO"></asp:TextBox>
        <asp:Button ID="btnLookupWO" runat="server" Text="Lookup W/O" Font-Size="12px" ValidationGroup="Validate_WO" OnClick="btnLookupWO_Click" />
        <asp:CustomValidator ID="valWO" runat="server" ControlToValidate="txtWO" ErrorMessage="Workorder is not valid"
            SetFocusOnError="True" ValidateEmptyText="True" OnServerValidate="valWO_ServerValidate" ValidationGroup="Validate_WO"></asp:CustomValidator><br />
        <asp:GridView ID="grdWOinfo" runat="server" Height="22px">
        </asp:GridView>
        <br />
        <asp:Label ID="lblBcodeMat" runat="server" Text="Material Barcode:" Visible="False"></asp:Label>
        <asp:TextBox ID="txtBcodeMat" runat="server" Font-Size="12px" Visible="False" Columns="12" MaxLength="12" ></asp:TextBox>&nbsp;
        <asp:Button ID="btnVerifyMat" runat="server" Text="Verify Material" Font-Size="12px" Visible="False" OnClick="btnVerifyMat_Click" /><br />
        <asp:Image
            ID="imgLightMat" runat="server" ImageUrl="http://intranet.cpi.com/_i/light_y.jpg" Visible="False" />
        <asp:DataList ID="DataList1" runat="server">
            <ItemTemplate>
                Itemno: <%#Eval("Itemno") %><%# Eval("Rev") %>
            </ItemTemplate>
        </asp:DataList>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:Label ID="lblBcodeColor" runat="server" Text="Colorant Barcode:" Visible="False" ></asp:Label>
        <asp:TextBox ID="txtBcodeColor" runat="server" Visible="False" Font-Size="12px" Columns="12" MaxLength="12" ></asp:TextBox>&nbsp;
        <asp:Button ID="btnVerifyColor" runat="server" Text="Verify Colorant" Font-Size="12px" Visible="False" /><br />
        <asp:SqlDataSource ID="srcMaterials" runat="server" ConnectionString="<%$ ConnectionStrings:conIqora %>"
            ProviderName="<%$ ConnectionStrings:conIqora.ProviderName %>"
            SelectCommand="SELECT V_SCHED.WORKORDER_ID AS WO, STANDARD.MFGNO, TRIM(ARINVT_MAT.ITEMNO) || '' || TRIM(ARINVT_MAT.REV) AS MATNO, TRIM(ARINVT_COLOR.ITEMNO) || '' || TRIM(ARINVT_COLOR.REV) AS COLORNO FROM V_SCHED V_SCHED, STANDARD STANDARD, ARINVT ARINVT_MAT, PARTNO PARTNO, PTOPER PTOPER, OPMAT OPMAT, ARINVT ARINVT_COLOR WHERE V_SCHED.STANDARD_ID = STANDARD.ID (+) AND STANDARD.ARINVT_ID_MAT = ARINVT_MAT.ID (+) AND STANDARD.ID = PARTNO.STANDARD_ID (+) AND PARTNO.ID = PTOPER.PARTNO_ID (+) AND PTOPER.SNDOP_ID = OPMAT.SNDOP_ID (+) AND OPMAT.ARINVT_ID = ARINVT_COLOR.ID (+) AND (ARINVT_COLOR.CLASS (+) = 'CL') AND (OPMAT.SEQ (+) = 1)" filterexpression="WO = '{0}'">
            <FilterParameters>
                <asp:ControlParameter ControlID="txtWO" Name="newparameter" PropertyName="Text" />
            </FilterParameters>

        </asp:SqlDataSource>
        <asp:SqlDataSource ID="srcLbl_Mat" runat="server" ConnectionString="<%$ ConnectionStrings:conIqora %>" ProviderName="<%$ ConnectionStrings:conIqora.ProviderName %>" SelectCommand="SELECT ITEMNO, REV, SERIAL FROM MASTER_LABEL WHERE CLASS IN ('PL','RG')" FilterExpression="SERIAL = '{0}'">
            <FilterParameters>
                <asp:ControlParameter ControlID="txtBcodeMat" Name="newparameter" PropertyName="Text" />
            </FilterParameters>
        </asp:SqlDataSource>
       
    </div>
    </form>
</body>
</html>


I still get teh same error message as before in the same line. Object reference not set to an instance of an object.

Dim itemNo As String = CType(Me.DataList1.Items(0).DataItem, DataRowView)("Itemno")

It is the third line inside the btnVerifyMat_Click
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19647061
Did you try putting that in Page_Load?

Bob
0
 
LVL 1

Author Comment

by:bhorlings
ID: 19648470
Yes. and I received an error that you cannot check the Is.PageValid in the page_load.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 19657771
Well, my friend, the timing is crucial here, so you have to set the DataSource and DataBind before this will work.

Bob
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

807 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