Need help migrating If..Then.. Else statement from Classic ASP to .NET

How would I replicate the following Classic ASP code in VB.NET?

<% If isNull(rs("client_website")) OR rs("client_website") = "" Then %>
<br />
<% Else %>
<a target="_blank" href="<%=rs("client_website")%>">view website</a><br />
<% End If %>
RegedekAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jens FiedererTest Developer/ValidatorCommented:
One way of doing this would be to include a literal control, call it literal1

In the code behind, do

If isNull(rs("client_website")) OR rs("client_website") = "" Then
   literal1.Text = "<br/>"
else
   literal1.text = "<a target='_blank' href='<" + rs("client_website") + ">'>view website</a><br />"
end if
0
RegedekAuthor Commented:
I'm VERY new to .NET (Only my second day of exposure)...  So I have some additional questions...

To include a literal control would the vb code behind look something like this?
Dim Literal1 As Object
Literal1 = New Project1.Class1

Or am I doing this incorrectly?

Another question...
Can I still use isNull - or should I use IsDBNull (for instance):
If IsDBNull("client_website") OR ("client_website") = "" Then


And lastly...
What would the HTML markup look like - could/would I use an asp label to display it?
<asp:label id="Literal1" runat="server"></asp:label>

Not sure if it will help to answer my question, but I'm including the odbc connection code just in case:

Dim connStr As String = ConfigurationManager.AppSettings("DSN1").ToString()
Dim dbconn As New OdbcConnection(connStr)

    Sub Page_Load()
        Select Request("ToDo")

            '***********
            Case "ViewEvent"
            '***********
               
                Dim sql As Object
                Dim dbcomm As Object
                Dim dbread As Object
                dbconn.Open()
                sql = "SELECT * FROM Events WHERE id=" & Int(Request("eventid"))
                dbcomm = New OdbcCommand(sql, dbconn)
                dbread = dbcomm.ExecuteReader()
                ViewMyEvent.DataSource = dbread
                ViewMyEvent.DataBind()
                dbread.Close()
                dbconn.Close()

Any help is appreciated...  Thanks in advance.
0
Jens FiedererTest Developer/ValidatorCommented:
You can literally just declare an <asp:literal  in your .aspx file.

<asp:Literal ID="Literal1" runat="server"></asp:Literal>

Or you can do in your code behind


        Dim literal1 As New Literal()
        Controls.Add(literal1)

But it's much easier to control the placement of your literal the first way.
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Jens FiedererTest Developer/ValidatorCommented:
isdbnull is ONLY used for columns in a row from a table you got back from the database, not for other objects.
0
RegedekAuthor Commented:
These are in fact columns being pulled from a database table, so I should swap isNull with isDBNull correct?
0
Jens FiedererTest Developer/ValidatorCommented:
Correct.
0
RegedekAuthor Commented:
I apologize for my high level of .NET ignorance here...  Please bear with me...

I made the changes you suggested.  When I attempt to load the page however, I get the following error:
'rs' is not declared. It may be inaccessible due to its protection level.

So my next question is: What do I use in place of rs() in .NET (as below)?
If IsDBNull(rs("client_website")) Or rs("client_website") = "" Then
          literal1.Text = "<br/>"
Else
          literal1.Text = "<a target='_blank' href='<" + rs("client_website") + ">'>view website</a><br />"
End If

If I remove the "rs" from the above code and just leave the field names - the page will load up, but the asp:literal does not display for those records in which the client_website field contains data.
0
Jens FiedererTest Developer/ValidatorCommented:
rs needs to be a datarow or similar, so if you did:

                Dim sql As Object
                Dim dbcomm As Object
                Dim dbread As Object
                dbconn.Open()
                sql = "SELECT * FROM Events WHERE id=" & Int(Request("eventid"))
                dbcomm = New OdbcCommand(sql, dbconn)
                reader = dbcomm.ExecuteReader()
                 If reader.HasRows Then
                        Do While reader.Read()
                                If IsDBNull(reader("client_website")) Or IsDBNull(reader("client_website"))= "" Then
                                              ''' whatever
                                end if
                        Loop
                  end if


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RegedekAuthor Commented:
Worked perfectly!
Thanks for your help... Much appreciated!
0
Jens FiedererTest Developer/ValidatorCommented:
My pleasure, have fun with .NET.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.