Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Help writing conditional blocks

Reply
Thread Tools

Help writing conditional blocks

 
 
estafford
Guest
Posts: n/a
 
      08-19-2003
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??


 
Reply With Quote
 
 
 
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      08-19-2003
"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??
>
>



 
Reply With Quote
 
 
 
 
estafford
Guest
Posts: n/a
 
      08-19-2003
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "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??
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM
Conditional html blocks Richard Frenkel ASP .Net 2 01-10-2005 07:09 PM
procs/blocks - blocks with procs, blocks with blocks? matt Ruby 1 08-06-2004 01:33 AM
Conditional except: blocks Robert Brewer Python 2 01-02-2004 07:20 PM



Advertisments