Help writing conditional blocks

Discussion in 'ASP .Net' started by estafford, Aug 19, 2003.

  1. estafford

    estafford Guest

    I am having trouble writing a conditional block using ASP.NET and C#.

    I am trying to do something like this:
    1. if page is PostBack
    - transfer to another page

    2. if not postback
    - connect to database and get information using a querystring id and create
    a DataReader (as DR).
    - generate a Form to display using values from the database query.

    The problem is that I get an error:
    The name 'DR' does not exist in the class or namespace 'ASP.contact_aspx'

    Because the page is not postback, the DataReader object is not created.
    Is there any way around this?

    I assumed that the code in condition 2 would be skipped because the
    condition was false but it seems to trying to run through it anyway.
    This process works in classic ASP but I cannot get it to work in ASP.NET.

    I'd like to try to keep this confined to one page.
    Suggestions??
     
    estafford, Aug 19, 2003
    #1
    1. Advertising

  2. "estafford" <estafford your pants @newmancom.com> wrote
    > I am having trouble writing a conditional block using ASP.NET and C#.
    > I am trying to do something like this:
    > 1. if page is PostBack
    > - transfer to another page
    > 2. if not postback
    > - connect to database and get information using a querystring id and create
    > a DataReader (as DR).
    > - generate a Form to display using values from the database query.
    >
    > The problem is that I get an error:
    > The name 'DR' does not exist in the class or namespace 'ASP.contact_aspx'
    >


    Did you include the "Imports System.Data.SqlClient" statement (for VB.NET) or
    "using System.Data;" statement (for C#) at the top of your code-behind file?

    Also, keep in mind, when you DIM an var in an IF statement, then that var only
    has scope within the IF statement block. Same is true for TRY CATCH blocks...

    --

    Thanks,
    Carl Prothman
    Microsoft ASP.NET MVP
    http://www.able-consulting.com


    > Because the page is not postback, the DataReader object is not created.
    > Is there any way around this?
    >
    > I assumed that the code in condition 2 would be skipped because the
    > condition was false but it seems to trying to run through it anyway.
    > This process works in classic ASP but I cannot get it to work in ASP.NET.
    >
    > I'd like to try to keep this confined to one page.
    > Suggestions??
    >
    >
     
    Carl Prothman [MVP], Aug 19, 2003
    #2
    1. Advertising

  3. estafford

    estafford Guest

    Bingo!!
    Thanks Carl. Turns out I did not declair the DR variable outside the
    function.
    I assumed it was something more difficult and overlooked the obvious.

    Such is the learning process...
    Thanks Again.

    "Carl Prothman [MVP]" <> wrote in message
    news:...
    > "estafford" <estafford your pants @newmancom.com> wrote
    > > I am having trouble writing a conditional block using ASP.NET and C#.
    > > I am trying to do something like this:
    > > 1. if page is PostBack
    > > - transfer to another page
    > > 2. if not postback
    > > - connect to database and get information using a querystring id and

    create
    > > a DataReader (as DR).
    > > - generate a Form to display using values from the database query.
    > >
    > > The problem is that I get an error:
    > > The name 'DR' does not exist in the class or namespace

    'ASP.contact_aspx'
    > >

    >
    > Did you include the "Imports System.Data.SqlClient" statement (for VB.NET)

    or
    > "using System.Data;" statement (for C#) at the top of your code-behind

    file?
    >
    > Also, keep in mind, when you DIM an var in an IF statement, then that var

    only
    > has scope within the IF statement block. Same is true for TRY CATCH

    blocks...
    >
    > --
    >
    > Thanks,
    > Carl Prothman
    > Microsoft ASP.NET MVP
    > http://www.able-consulting.com
    >
    >
    > > Because the page is not postback, the DataReader object is not created.
    > > Is there any way around this?
    > >
    > > I assumed that the code in condition 2 would be skipped because the
    > > condition was false but it seems to trying to run through it anyway.
    > > This process works in classic ASP but I cannot get it to work in

    ASP.NET.
    > >
    > > I'd like to try to keep this confined to one page.
    > > Suggestions??
    > >
    > >

    >
    >
     
    estafford, Aug 19, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Frenkel

    Conditional html blocks

    Richard Frenkel, Jan 10, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    6,471
    Karl Seguin
    Jan 10, 2005
  2. Arjen
    Replies:
    3
    Views:
    471
    Scott Allen
    Feb 27, 2005
  3. Robert Brewer

    Conditional except: blocks

    Robert Brewer, Jan 2, 2004, in forum: Python
    Replies:
    2
    Views:
    446
  4. matt
    Replies:
    1
    Views:
    296
    George Ogata
    Aug 6, 2004
  5. Steven Taylor
    Replies:
    9
    Views:
    279
    Brian Candler
    Apr 27, 2009
Loading...

Share This Page