Link to home
Create AccountLog in
Avatar of sammySeltzer
sammySeltzerFlag for United States of America

asked on

I think I am losing it...

This has always been fairly simple.

I click a link and pass an id via querystring to another page.

That other page is exposed to the browser with data associated with id passed via querystring.

In this case, I am getting a blank page.

I need a new set of eyes to pick me up.

Thanks in advance.

Here are the sets of files.

The first one news.aspx.vb processes news info and attempts to pass the details to newsdetails page via querystring.

The second attachment is the newsdetails page that *should* display data associated with passed querystring.


Option Explicit On

Imports System
Imports System.Data
Imports System.Data.OleDB
Imports System.Xml
Imports System.Web
Imports System.Drawing
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.Page
Imports Microsoft.VisualBasic
Imports System.Web.HttpApplication
Imports System.Web.HttpResponse
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Mime
Imports System.Net.Mail.SmtpClient
Imports System.Web.Security
Partial Class _Default
    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


    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
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim cmdcommand As OleDBCommand
        Dim objDataReader As OleDBDataReader
        Dim strSQL As String
        Dim Conn As OleDbConnection
        Conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("App_Data\Countries.mdb"))
        Conn.Open()
        'Check which action were selected, edit the dept
        strSQL = "SELECT newsId, datecreated, newtitle FROM tbl_News WHERE Date() >= dateCreated order by dateCreated desc"
        'Response.Write(strSQL)
        'Response.End()
        cmdcommand = New OleDbCommand(strSQL, Conn)

        'Get a datareader
        objDataReader = cmdcommand.ExecuteReader()

        While objDataReader.Read()
            NewsScroller1.newsText = "<a href='#' OnClick=" & "javascript:window.open('newsDetail.aspx?NewsID=" & objDataReader.GetValue(0) & "','NewsDetail','width=400,height=400;toolbar=no;');" & "><font face='verdana' size='2' color='#184D68'>" & objDataReader.GetValue(1) & "</a>&nbsp;&nbsp;-&nbsp;&nbsp;" & objDataReader.GetValue(2).ToString() & "</font><br><br>"

        End While

    End Sub
End Class

[code]Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data.OleDB

	''' <summary>
	''' Summary description for newsDetail.
	''' </summary>
Partial Class newsDetail
    Inherits System.Web.UI.Page
    'Protected tblDetail As System.Web.UI.HtmlControls.HtmlTable
    'Protected rowNewsDetail As System.Web.UI.HtmlControls.HtmlTableRow
#Region " Web Form Designer Generated Code "

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

    End Sub


    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 Object, ByVal e As System.EventArgs)

        Dim strSQL As String
        Dim Conn As OleDbConnection

        ' Put user code to initialize the page here
        Conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("App_Data\Countries.mdb"))
        strSQL = "SELECT newsDetail FROM tbl_NewsDetail WHERE newsId=" & Convert.ToInt32(Request.QueryString("NewsId"))
        Response.Write(strSQL)
        Response.End()
        Dim cellNewsDetail As New HtmlTableCell()
        Dim myComd As New OleDbCommand(strSql, Conn)
        Dim sqlRdr As OleDBDataReader
        Try
            Conn.Open()
            sqlRdr = myComd.ExecuteReader()
            If sqlRdr.Read() Then
                cellNewsDetail.InnerText = sqlRdr.GetValue(0).ToString()
                rowNewsDetail.Cells.Add(cellNewsDetail)
            Else
                Response.Write("No Record found in the detail table")
            End If
            sqlRdr.Close()
        Catch msg As Exception
            Response.Write(msg.Message)
        Finally
            'close connection
            Conn.Close()
        End Try
    End Sub

End Class[/code]

Open in new window

SOLUTION
Avatar of ALaRiva
ALaRiva
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of sammySeltzer

ASKER

Thanks for the reply but no love.

I only fully qualify the fieldname I am interesting in displaying which is the newsdetails field.

I did, however, fully qualify all but no dice.

Here is the source view and you can see that the newsID value is correctly passed to the newsDetails page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>news Detail</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="VB">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body>
		<form name="Form1" method="post" action="newsDetail.aspx?NewsID=1" id="Form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTI0NzA0OTk1NWRkNiGozIIHY+GTOwxDPLGyGyfb0ds=" />

			<table id="tblDetail">
	<tr id="rowNewsDetail">
	</tr>
</table>

		</form>
	</body>
</HTML>

Open in new window

It doesn't even appear that your Load() is even executing.

You have a Response.Write of the strSQL as one of the first lines, but I see it no where in the page source that you provided.

Can you confirm that the Load() is executing?
SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Also, I'm seeing how you are creating the table ROWS and CELLS, but they only exist in the code, you don't have anything there adding them to write them to the page or to a table object that is on the page.

- Anthony
saige, still no cigar.

Anthony, where should I add this?

Still new to this technology.

thanks guys for assistance.
Add breakpoint at the page load event and step through the code to see what's going on

http://blogs.msdn.com/b/zainnab/archive/2010/04/25/set-or-remove-a-breakpoint-vstipdebug0016.aspx

For now, just change this...

            If sqlRdr.Read() Then
                cellNewsDetail.InnerText = sqlRdr.GetValue(0).ToString()
                rowNewsDetail.Cells.Add(cellNewsDetail)
            Else
                Response.Write("No Record found in the detail table")
            End If

Open in new window


to this...

            If sqlRdr.Read() Then
                Response.Write(sqlRdr.GetValue(0).ToString())            
            Else
                Response.Write("No Record found in the detail table")
            End If

Open in new window


See if that at least gets you the data to the screen.

- Anthony
Nope,

just open a new window for newsdetails page but blank screen.

you view source and you see this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>news Detail</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="VB">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body>
		<form name="Form1" method="post" action="newsDetail.aspx?NewsID=1" id="Form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTI0NzA0OTk1NWRkNiGozIIHY+GTOwxDPLGyGyfb0ds=" />

			<table id="tblDetail">
	<tr id="rowNewsDetail">
	</tr>
</table>

		</form>
	</body>
</HTML>

Open in new window

Found it. As I said earlier, it didn't look like your code from the Page_Load was firing.

In the code for the form, change this...
    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

Open in new window


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

    this.Load += new System.EventHandler(this.Page_Load);

    End Sub

Open in new window


That should have been automatically created, but it wasn't apparently. This basically wires the page to know that when it Loads you want to fire the Page_Load event.

Give that a go.

- Anthony
Hi guys,

Thanks for your continued support.

Just items to share with you.

First, the code you posted is in c#. I am using vb flavor.

That sub, sub initializeComponent() is giving me all of the following errors below.

'Private Sub InitializeComponent()' has multiple definitions with identical signatures.
Name 'this' is not declared.
'System.EventHandler' is a delegate type and requires a single 'addressof' expression as the only argument to the constructor.


I tried converting the code to vb but I was getting error similar to 'addressof' expression error.

Any thoughts what we could try next?

Agains for all the help.
I find it interesting that you are not seeing this on your newsdetail page:

Response.Write(strSQL)

Which, in your example above, would translate to:

SELECT newsDetail FROM tbl_NewsDetail WHERE newsId=1

Which in the source would show as:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>news Detail</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="VB">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body>
		<form name="Form1" method="post" action="newsDetail.aspx?NewsID=1" id="Form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTI0NzA0OTk1NWRkNiGozIIHY+GTOwxDPLGyGyfb0ds=" />
SELECT newsDetail FROM tbl_NewsDetail WHERE newsId=1
			<table id="tblDetail">
	<tr id="rowNewsDetail">
	</tr>
</table>

		</form>
	</body>
</HTML>

Open in new window

Noticed you have these commented out:

    'Protected tblDetail As System.Web.UI.HtmlControls.HtmlTable
    'Protected rowNewsDetail As System.Web.UI.HtmlControls.HtmlTableRow

Any reason why?  Also try commenting out these two:

        Response.Write(strSQL)
        Response.End()

And add something like this:

       Response.Write("This is a test message")

-saige-

Yes, I commented those out because I get error message that they have already been declared.

I get that all the time in my other .net apps and once I comment them out, all is well.

I am pretty confident that Anthony's code:

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

    this.Load += new System.EventHandler(this.Page_Load);

    End Sub

would work once I can convert it to a "working" vb version.
This is the vb.net equivalent:




<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
	Me.Load += New System.EventHandler(Me.Page_Load)
End Sub

Open in new window

I had the exact code and I was getting the following errors:

Error      1      'Public Event Load(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.


Error      2      'System.EventHandler' is a delegate type and requires a single 'addressof' expression as the only argument to the constructor.

I took the code out because I couldn't fix the error.

Errot 1 is pointing to this -> Me.Load +=

Error 2 is pointing to  this -> (Me.Page_Load)

A bit  frustrating.
Did you try my suggestion ( 34450904 ) with your original code?
Yes, I did.

I am not sure what it is supposed to do when I am getting errors.

I put the breakpoint, press either F10 or F11 then the alert box, "there were build errors. Do you want to continue?"

If I press yes, then I get:
BC32022: 'Public Event Load(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

then a red line with:
Line 27:         Me.Load += New System.EventHandler(Me.Page_Load)

These are the 2 modules:

#Region "Web Form Designer generated code"

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Load += New System.EventHandler(Me.Page_Load)
    End Sub

    Protected Overrides Sub OnInit(ByVal e As EventArgs)
        '
        ' CODEGEN: This call is required by the ASP.NET Web Form Designer.
        '
        InitializeComponent()
        MyBase.OnInit(e)
    End Sub
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
so, remove these?
#Region "Web Form Designer generated code"

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Load += New System.EventHandler(Me.Page_Load)
    End Sub

    Protected Overrides Sub OnInit(ByVal e As EventArgs)
        '
        ' CODEGEN: This call is required by the ASP.NET Web Form Designer.
        '
        InitializeComponent()
        MyBase.OnInit(e)
    End Sub
Remove this line

 Me.Load += New System.EventHandler(Me.Page_Load)
By the way, the += is used in C# to add handlers. In VB.NET, we use the AddHandler statement

AddHandler Me.Load, AddressOf Page_Load
FOUND IT!

Man, this is so embarassing guys; please don't laugh.

I have to say that YOU codeCruiser led me to the problem, and ultimate solution.

However, I want to thank all of you for your contributions.

The issue is the page_load() even on newsDetail.aspx code file.

It doesn't have the event handler.

I needed to add Handles MyBase.Load and for the life or me, it didn't occur to me to do so until codeCruiser's  post:

Try it with your ORIGINAL code(the one in question area). You already have the Handles clause so you dont need to add handler manually.

Again, thanks to all of you.

Now, you know that no matter how much you know programming, there is a language out there that will "get you".



Happens to everyone :-)

All the symptoms pointed to this but your original code had Handles class so I suggested to use a breakpoint to make sure that the code is being hit.