Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Thursday, March 29, 2012

newbie - need early guidance

HI all

I am very new to coding and although I know how things work and what you can do with code and visual design I don't really have experience!

I would like some very basic advise on what coding front end to look into i.e. c++, VB, Web etc.

I am interested in learning to develop a basic system for my cafe that would enable a customer to go through a graphical experience in building their coffee order. I would ideally like to create something that would work well IN the cafe via a touchscreen or on the Internet from their desktop.

Now this is only basic stuff I'm not looking to build a go to market system but just something that applies to my daily life while giving me something new and challenging to look into.

Any guidance would be much appreciated!

Alfo,

I'm glad to hear that you would like to educate yourself in designing / programming / implementing a website.
In my opinion it is this very early stage that is the most important.
It is in this stage that you decide exactly what it is that your site will do and how it will do it.

My advice is to sit down with a pencil and paper and decide on some of the following options:
Will users be required to:
1) Login / Register - if yes
a) before they begin the process of placing an order
b) if they try to place an order
2) How will you accept payment? Cash, credit cards, e-checks, paypal...
3) What are all of the other high level functionalities that you'd like your site to offer?

Regarding what language to use, I much prefer C# (no particular reason, VB.Net is also a great and simple language to use).
It will have no impact on how your site looks to your customers. This is something that is purely up to you.
I do however recommend 2 books (possibly 3 or 4) that will help you greatly in reducing your learning curve and aid you in applying new concepts / ideas in real life situations:
1) Beginning ASP.Net e-commerce in c#. I have the 2005 edition. I'm not sure if there is a newer version or not.
2) Beginning asp.Net in C#.
3) Any beginners SQL book.
4) Any book for HTML / CSS.

If you have any questions or would like any advice let me know.
I used the first 2 books to help me build my first .Net website (https://www.theproductpad.com) and am very greatful for the help that these books gave me.

Good luck,
Michael


thanks

i remember the days when I wrote basic code for ZX Spectrum but now im a little lost!!

I will look into the books.

Aflo

Newbie - Please be Nice

Hey everyone..

I've read a few posts in here, and none of them actually answered my question... I am a complete newbie to .NET ... I code XHTML & CSS for a large company and have some knowledge of ASP & SQL.

My question is where shall I start? What should be the first thing I learn and where should I get the info... I have just ordered ASP.NET 2 For Dummies and also VB.NET for Dummies... I have downloaded Visual Web Developer Express Edition and am VERY keen to start.

I hope I don't annoy too many of you with stupid questions once I get going...Wink

Hi, There is always a start point!!

There is a nice book ASP.NET 1.1 Unleashed and now a new version ASP.NET Unleashed 2.0. Both books are best recommended.

There is also a good startng point:Learn ASP.NET

You should start with VWD, install it and start with it as soon as possible.

Feel free always to ask whatever you want. I am sure all are ready to help!

Regards


Actually I'm going to jump into this question and ask as well, I am new to asp, sql, and vb as well.

I basically was given a project that required all three so I have been learning as I go, do you (or anyone with the experience) recommend an order (I have asp.net 2.0 unleashed it is a good book)such as learning vb.net first then moving onto asp, or can you learn both at the same time. I have been working on this project so I have not had the luxury of time to really learn, I've just had to do, and while I have learned some (I know more now than I did when I started), after this project gets done, I plan on actually going back and learning the language(s). Any particular order in learning or can you learn them both concurrently and have it worked out, I'll admit more than once I have gotten lost in code trying to figure out which part was asp and which part was vb, not to mention there are to many commands I parrot without actually understanding what they actually do. I have been using notepad, and dreamweaver (in code mode) because that is the best way for me to learn something (I learn HTML and CSS before I learn dreamweaverBig Smile )


Thats a good question... I wondered whether to learn VB.NET first and then move on - But I am creating web applications so really I should learn ASP.NET first and try to integrate VB.NET as I go.. Luckily I do know a very small bit of VBScript from using it with ASP which I hope will help me in the long run (hehehe.. I hope :-) ...

Are there any video tutorials for absolute beginners?? As I started watching the first beginners tutorial and even that says VWD Tutorial for VB programmers or something like that ...Huh? .. If I could find some video tutorials for people who don't know VB script first then that'd be cool ... If not I'll struggle by...

Still are there things I should make a point of getting my head round in .NET?? For example in ASP VBScript the pre-built functions are something you HAVE to know about if you want to suceed?? Any advice...

(Thanks for the home page link too...Smile)
Anyone... Surely you clever lot could give us a bit more info as to maybe where you guys n gals started??Embarrassed

Hi,

You might find this link (including video tutorials) helpful:

http://weblogs.asp.net/scottgu/archive/2006/02/26/Great-ASP.NET-2.0-Tutorial-Videos-Online.aspx

Also, I started with Professional C# by Wrox publication and learnt the language first and then came to Web programming. You can do both simultaneously, no issues. Just keep the fire inside you burning !

Regards,

Vivek


You guys should delve into VB a little bit, learn about its structure, functions, classes, Import etc. I think AT MOST a week should be enough (and that's a lot of time to learn it), and then you can start playing with ASP .Net!

Smiles.


ok... So VB 2005 or VB.NET?

VB 2005 means VB.NET ( visual studio 2005 ) on .NET framework 2.0.

-Vivek


Thanks for that...

dotnet_lee:

Anyone... Surely you clever lot could give us a bit more info as to maybe where you guys n gals started??Embarrassed

Assembler on a DEC PDP-11. From there, Bally Basic, Z-80 assembler, GW Basic, 8086/88 assembler, Basic-A, LISP, LOGO, a bit of Pascal, Cobol and Fortran, C, Visual Basic, C+, VBA, Perl, HTML, C++, Javascript, VBscript, how to do "Hello World!" in Jscript, VB.NET, CSS, a week of hating Python, C#, TSQL, one Java applet and a bunch of macro or scripting technologies along the way. And I still can't program my way out of a paper bag. :)

To get started you need to learn programming structure. You'll also need some basic OOP background to understand classes and inheritance. Learning those will take some kind of language, since you can't easily learn a pre-test or post-test loop without a language to program a loop in. Start with VB or C, and stick with that until you can do everything. Then translate that into the other one.

Get a copy of Visual Web Developer and never use drag and drop. Write the code. Let VWD mark up your improper syntax, even prompt you with Intellisense, but don't let a wizard do anything and forget any control properties except the main window in Source view. Once you've written a decent learning app, start a new one and drag and drop to create the same app. You'll see where to edit code by hand, what properties you can default and what parts of the IDE will make life easier instead of hiding the innards you're trying to learn.

Forget a week. Plan on a lifetime of learning and relearning. Take a class every year or two, buy a few books each year on new technologies or techniques and twice a year take a week to design and code an app you've never done before. Do it for your church, school or local charity. Sit with the users and watch where they screw up your carefully crafted app. Fix it so they can't screw up. Then make it pretty. Document it fully so that in a year or two you can go back and update it for them. If it's really good and widely useful, release it as open source and see waht people who you've never met will do to improve your code. And learn from them.

Above all, ask questions. Whenever you need to. Research the topic first so you don't ask dumb questions, and try to solve the problem yourself, but don't stay stuck on something when there is someone you can ask.

Good luck.

Jeff


dotnet_lee:

Anyone... Surely you clever lot could give us a bit more info as to maybe where you guys n gals started??Embarrassed

The videos in the links below covers most of what you need to know because you already know web application. Then get a comprehensive book like Asp.net 2.0 Unleashed and you are ready. It is not rocket science.

http://weblogs.asp.net/scottgu/search.aspx?q=Video+tutorials&p=1

http://www.asp.net/learn/withpss/default.aspx?tabid=63

http://www.asp.net/learn/videos/default.aspx?tabid=63

Read the tutorials at the end of the first link below for OOAD(object Oriented analysis and design), while you wait for the Video version of Craig Larman's also very comprehensive OOAD book which you can order from the second link.

http://www.objectsbydesign.com/tools/certification.html#resources
http://www.phptr.com/bookstore/product.asp?isbn=0130479500&aid=686ef932-f921-4820-99b0-fe6a0ad6f082&rl=1

Hope this helps and happy coding.


Hi there.

Being quite new to .NET and from the same background as you i do understand what you need!
I started at the learning zone here, and at the VWD learning site here:http://msdn.microsoft.com/vstudio/express/vwd/learning/default.aspx

A set of really neat instructionsvideos for C# and VB lead you the way to a finished product while describing most of the essentials.. Could it be better that that?

Happy coding!Cool

Newbie -- pls help

Hi all,

Reali need some help here.

I'm using <repeaterto display few thing taken from the dB.
1. hidden field, which contains the Language code (stored in dB)
2. Textbox

Code goes:

<asp:repeater id="myRepeater" runat="server">
<itemtemplate>
<asp:panel id="pnlCountry" runat="server">
<asp:table>
<tr>
<td>
<asp:label id="lblCounty" runat="server" text="T&Cs: "></asp:label><br>
<%# Container.DataItem("LanguageCode") %>
</td>
<td>
<asp:textbox id="txtTnC" runat="server" textmode="multiline" rows="10"
columns="45"></asp:textbox>
</td>
</tr>
<tr><td>
<INPUT id="hdnLanguage" type="hidden" runat="server" NAME="hdnAltLanguage"
value=<%# Container.DataItem("LanguageCode") %>>
</td>
</tr>
</asp:table>
</asp:panel>
</itemtemplate>
</asp:repeater>

OnClick of a button, i want to get the values entered in the textfields for
the different languages.

How do i do that? What events to use??

Pls help me!!!

Thanx lotz..

RegarDx..Well if you want to do something when someone click a button then put it in
the OnClick event handler. If you want to access the values in the labels
and textboxes in the repaeater control then you would use the command

myRepeater.FindControl("ControlID")

This will return a reference to the relevent control, although all controls
within the parent container (i.e. myRepeater) must have unique IDs.

your code for the asp:table markup is wrong. You have created an asp:table
but left out an ID and a runat=server which are required. You have also used
HTML row and column markup, to create rows and columns in an asp:table you
use <asp:TableRowand <asp:TableCell not <trand <td>.

"siLver" wrote:

Quote:

Originally Posted by

Hi all,
>
Reali need some help here.
>
I'm using <repeaterto display few thing taken from the dB.
1. hidden field, which contains the Language code (stored in dB)
2. Textbox
>
Code goes:
>
<asp:repeater id="myRepeater" runat="server">
<itemtemplate>
<asp:panel id="pnlCountry" runat="server">
<asp:table>
<tr>
<td>
<asp:label id="lblCounty" runat="server" text="T&Cs: "></asp:label><br>
<%# Container.DataItem("LanguageCode") %>
</td>
<td>
<asp:textbox id="txtTnC" runat="server" textmode="multiline" rows="10"
columns="45"></asp:textbox>
</td>
</tr>
<tr><td>
<INPUT id="hdnLanguage" type="hidden" runat="server" NAME="hdnAltLanguage"
value=<%# Container.DataItem("LanguageCode") %>>
</td>
</tr>
</asp:table>
</asp:panel>
</itemtemplate>
</asp:repeater>
>
>
OnClick of a button, i want to get the values entered in the textfields for
the different languages.
>
How do i do that? What events to use??
>
Pls help me!!!
>
Thanx lotz..
>
RegarDx..
>
>

Newbie - Protecting source code

If I create an ASP.NET (c#) web application, how can I prevent my code being
ripped off when I load it onto a 3rd party web server? (Someone copying the
.cs files, and removing them)
Is there a way to compile these .cs files for the ASP.NET pages to read.If you're using VS.NET, compile the project,
and only upload the dll's and .aspx files to your
server or, if you're not using VS.NET, compile
the assemblies ( dlls ) from the command line
and deploy them, with your .aspx files, to the server.
Juan T. Llibre
ASP.NET MVP
===========
"Fronky" <nospam@.nospam.com> wrote in message
news:OJmXokTCFHA.2032@.tk2msftngp13.phx.gbl...
> If I create an ASP.NET (c#) web application, how can I prevent my code
> being
> ripped off when I load it onto a 3rd party web server? (Someone copying
> the
> .cs files, and removing them)
> Is there a way to compile these .cs files for the ASP.NET pages to read.
>
Sorted it! Thanks for your help!
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:uxQbcyTCFHA.1396@.TK2MSFTNGP14.phx.gbl...
> If you're using VS.NET, compile the project,
> and only upload the dll's and .aspx files to your
> server or, if you're not using VS.NET, compile
> the assemblies ( dlls ) from the command line
> and deploy them, with your .aspx files, to the server.
>
>
> Juan T. Llibre
> ASP.NET MVP
> ===========
> "Fronky" <nospam@.nospam.com> wrote in message
> news:OJmXokTCFHA.2032@.tk2msftngp13.phx.gbl...
>
Of course, if the security on the server is such that someone could view the
source code of your ASP.Net pages, you have a more serious problem.
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.
"Fronky" <nospam@.nospam.com> wrote in message
news:u5HmNDUCFHA.520@.TK2MSFTNGP09.phx.gbl...
> Sorted it! Thanks for your help!
>
> "Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
> news:uxQbcyTCFHA.1396@.TK2MSFTNGP14.phx.gbl...
>
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:O$DN%23pVCFHA.3976@.tk2msftngp13.phx.gbl...

> Of course, if the security on the server is such that someone could view
> the source code of your ASP.Net pages, you have a more serious problem.
LOL! Absolutely!

Newbie - Protecting source code

If I create an ASP.NET (c#) web application, how can I prevent my code being
ripped off when I load it onto a 3rd party web server? (Someone copying the
..cs files, and removing them)
Is there a way to compile these .cs files for the ASP.NET pages to read.If you're using VS.NET, compile the project,
and only upload the dll's and .aspx files to your
server or, if you're not using VS.NET, compile
the assemblies ( dlls ) from the command line
and deploy them, with your .aspx files, to the server.

Juan T. Llibre
ASP.NET MVP
===========
"Fronky" <nospam@.nospam.com> wrote in message
news:OJmXokTCFHA.2032@.tk2msftngp13.phx.gbl...
> If I create an ASP.NET (c#) web application, how can I prevent my code
> being
> ripped off when I load it onto a 3rd party web server? (Someone copying
> the
> .cs files, and removing them)
> Is there a way to compile these .cs files for the ASP.NET pages to read.
Sorted it! Thanks for your help!

"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:uxQbcyTCFHA.1396@.TK2MSFTNGP14.phx.gbl...
> If you're using VS.NET, compile the project,
> and only upload the dll's and .aspx files to your
> server or, if you're not using VS.NET, compile
> the assemblies ( dlls ) from the command line
> and deploy them, with your .aspx files, to the server.
>
>
> Juan T. Llibre
> ASP.NET MVP
> ===========
> "Fronky" <nospam@.nospam.com> wrote in message
> news:OJmXokTCFHA.2032@.tk2msftngp13.phx.gbl...
> > If I create an ASP.NET (c#) web application, how can I prevent my code
> > being
> > ripped off when I load it onto a 3rd party web server? (Someone copying
> > the
> > .cs files, and removing them)
> > Is there a way to compile these .cs files for the ASP.NET pages to read.
Of course, if the security on the server is such that someone could view the
source code of your ASP.Net pages, you have a more serious problem.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Fronky" <nospam@.nospam.com> wrote in message
news:u5HmNDUCFHA.520@.TK2MSFTNGP09.phx.gbl...
> Sorted it! Thanks for your help!
>
> "Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
> news:uxQbcyTCFHA.1396@.TK2MSFTNGP14.phx.gbl...
>> If you're using VS.NET, compile the project,
>> and only upload the dll's and .aspx files to your
>> server or, if you're not using VS.NET, compile
>> the assemblies ( dlls ) from the command line
>> and deploy them, with your .aspx files, to the server.
>>
>>
>>
>>
>> Juan T. Llibre
>> ASP.NET MVP
>> ===========
>> "Fronky" <nospam@.nospam.com> wrote in message
>> news:OJmXokTCFHA.2032@.tk2msftngp13.phx.gbl...
>> > If I create an ASP.NET (c#) web application, how can I prevent my code
>> > being
>> > ripped off when I load it onto a 3rd party web server? (Someone copying
>> > the
>> > .cs files, and removing them)
>> > Is there a way to compile these .cs files for the ASP.NET pages to
>> > read.
>>>>
>>
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:O$DN%23pVCFHA.3976@.tk2msftngp13.phx.gbl...

> Of course, if the security on the server is such that someone could view
> the source code of your ASP.Net pages, you have a more serious problem.

LOL! Absolutely!

newbie - variable from code-behind to aspx page

Sorry for the question but I am a newbie of asp.net 2.0.
I have a variable in code behind and I would show it in aspx page (with
<% ... %> ).
How can I do it? or what is the best method for print db data in aspx page?
thanks
DamianoNormally you use controls and set their value programatically in codebehind.
Say
<asp:literal id="Name" runat="server" />
you could then do Name.Text = "SomeValue"
different controls fit different needs..the literal control shown above is
great for basic data.
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"Damiano Callegari" <yamne.it@.NOSPAMgmail.com> wrote in message
news:%23geTK9UFGHA.2012@.TK2MSFTNGP14.phx.gbl...
> Sorry for the question but I am a newbie of asp.net 2.0.
> I have a variable in code behind and I would show it in aspx page (with <%
> ... %> ).
> How can I do it? or what is the best method for print db data in aspx
> page?
> thanks
> Damiano
well you newbe in general or only in 2.0?
Because i always use a label in the page and in the code behind page i
do label.Text = myDbVar
But you can use simple as Response.Write(myDbVar)
But if there is any special way to do this in 2.0 i dunno.
And also if you new at ASP.NET, you can always use <%%> but in general
there is a better solution for this using ASP.NET code behind.
And also if you new at ASP.NET, you may get about compiled
code and WYSIWYG compiled code have CODE BEHIND the other dont
New to 2.0 or to ASP.NET?
I dont know if 2.0 have any new on how to do this but you can always
use
Response.Write(yourVar);
<%%> also works but its a legacy from ASP

newbie - variable from code-behind to aspx page

Sorry for the question but I am a newbie of asp.net 2.0.
I have a variable in code behind and I would show it in aspx page (with
<% ... %>).
How can I do it? or what is the best method for print db data in aspx page?

thanks
DamianoNormally you use controls and set their value programatically in codebehind.

Say

<asp:literal id="Name" runat="server" /
you could then do Name.Text = "SomeValue"

different controls fit different needs..the literal control shown above is
great for basic data.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Damiano Callegari" <yamne.it@.NOSPAMgmail.com> wrote in message
news:%23geTK9UFGHA.2012@.TK2MSFTNGP14.phx.gbl...
> Sorry for the question but I am a newbie of asp.net 2.0.
> I have a variable in code behind and I would show it in aspx page (with <%
> ... %>).
> How can I do it? or what is the best method for print db data in aspx
> page?
> thanks
> Damiano
well you newbe in general or only in 2.0?

Because i always use a label in the page and in the code behind page i
do label.Text = myDbVar

But you can use simple as Response.Write(myDbVar)

But if there is any special way to do this in 2.0 i dunno.

And also if you new at ASP.NET, you can always use <%%> but in general
there is a better solution for this using ASP.NET code behind.

And also if you new at ASP.NET, you may get confused about compiled
code and WYSIWYG compiled code have CODE BEHIND the other dont
New to 2.0 or to ASP.NET?

I dont know if 2.0 have any new on how to do this but you can always
use
Response.Write(yourVar);
<%%> also works but its a legacy from ASP

Monday, March 26, 2012

Newbie ? about Classes

I'm not entirely clear on when to create a class and when to just code subs and funcs. I'm getting pretty comfortable with the latter and am beging to wonder if I should be learning to write classes. Any thoughts would be apreaciated.
Thanks
Raif
This depends entirely on a combination of your goals and your preferences.

Classes are an excellent way to get some reusability out of your code that might apply to more than one web page, or even multiple applications. They can increase development time initially, but you may recover this time on future projects from reuse.

Using classes can also make your code more readable, and therefor more maintainable.

The biggest advantage to writing classes is that it gets you going with Object Oriented Programming. OOP is extremely important in .NET because as you create classes and such, you will begin to build a giant library that you and your team can re-use for future projects. If you do not practice OOP in .NET, you will be spending way to much time in writing the same code over and over again for different projects. For instance, creating Table controls, TableRow controls, TableCell controls can be tedious at times. This would call for a WebControlHelper class that you can reuse for all of your projects. Not only that, as you come up with better techniques for clean up and speed, you can make changes to that class and as long as the method signature and its return type doesn't change, all applications you used this helper for would benefit from it.

i.e.


public class WebControlHelper
{
public WebControlHelper
{

}

public Table CreateTable ()
{
return new Table();
}

public Table CreateTable (int numRows)
{
Table thisTable = null ;

try
{
thisTable = CreateTable();
for (int i=0;i<numRows;i++)
thisTable.Rows.Add(new TableRow());
}
catch (Exception e)
{ throw new Exception (e.ToString(), e); }
finally
{
thisTable.Dispose();
thisTable = null ;
}
}
}

This can go on and on to create quite a large helper class and it will save you time later. Let me know if I can be of further help. I'll be glad too!
AND - if you have subs or functions that you use over and over, you'd want to centralize them in a .vb or .cs file (depending on the language you're using)
That way, they're accessible to any aspx document in your application.
how do i include the cs/vb file containing my reusable functions and procedures?

i read that you can compile it to a dll and have it as part of your Imports. is there a way to do it without compiling?

thanks.

newbie ASP won't work

Hi,
I have just installed IIS on my XP SP2 machine.
This code (dreamweaver) doesn't work
<%@dotnet.itags.org. LANGUAGE="VBSCRIPT"" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
Good Afternoon<BR>
Welcome to this sample. It is approximately
<%=Time()%> at the server, Here
<body>
</body>
</html>
pls help
Jack"Jacky Luk" <jl@.knight.com> glsD:O7qvwDbkFHA.3968@.tk2msftngp13.phx.gbl...arkred">
> Hi,
> I have just installed IIS on my XP SP2 machine.
> This code (dreamweaver) doesn't work
> <%@. LANGUAGE="VBSCRIPT"" %>
____
I've spoted one error, but still doesn't work in preview

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=big5">
> </head>
> Good Afternoon<BR>
> Welcome to this sample. It is approximately
> <%=Time()%> at the server, Here
> <body>
> </body>
> </html>
> pls help
> Jack
>
Here's the revision
<%@. LANGUAGE="VBSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<body>
Good Afternoon<BR>
Welcome to this sample. It is approximately
<%=Time()%> at the server, Here
</body>
</html>
"Jacky Luk" <jl@.knight.com> glsD:O7qvwDbkFHA.3968@.tk2msftngp13.phx.gbl...arkred">
> Hi,
> I have just installed IIS on my XP SP2 machine.
> This code (dreamweaver) doesn't work
> <%@. LANGUAGE="VBSCRIPT"" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=big5">
> </head>
> Good Afternoon<BR>
> Welcome to this sample. It is approximately
> <%=Time()%> at the server, Here
> <body>
> </body>
> </html>
> pls help
> Jack
>
First, define "doesn't work." Describe symptoms, behaviors, error messages,
etc.
Second, this is the ASP.Net newsgroup. You want the ASP newsgroup,
microsoft.public.inetserver.asp.general.
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
The sun never sets on
the Kingdom of Heaven
"Jacky Luk" <jl@.knight.com> wrote in message
news:O7qvwDbkFHA.3968@.tk2msftngp13.phx.gbl...
> Hi,
> I have just installed IIS on my XP SP2 machine.
> This code (dreamweaver) doesn't work
> <%@. LANGUAGE="VBSCRIPT"" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=big5">
> </head>
> Good Afternoon<BR>
> Welcome to this sample. It is approximately
> <%=Time()%> at the server, Here
> <body>
> </body>
> </html>
> pls help
> Jack
>
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> glsD:eiDp6EekFHA.1048@.tk2msftn
gp13.phx.gbl...
> First, define "doesn't work." Describe symptoms, behaviors, error
> messages, etc.
> Second, this is the ASP.Net newsgroup. You want the ASP newsgroup,
> microsoft.public.inetserver.asp.general.
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> The sun never sets on
> the Kingdom of Heaven
> "Jacky Luk" <jl@.knight.com> wrote in message
> news:O7qvwDbkFHA.3968@.tk2msftngp13.phx.gbl...
the current time ,Time(), is not displayed
>
Jacky as ken Adviced this is ASP.NET newsgroup.
To display your time use:-
<%=Now()%>
Hope that helps
Patrick
*** Sent via Developersdex http://www.examnotes.net ***

newbie ASP wont work

Hi,
I have just installed IIS on my XP SP2 machine.
This code (dreamweaver) doesn't work

<%@dotnet.itags.org. LANGUAGE="VBSCRIPT"" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
Good Afternoon<BR>
Welcome to this sample. It is approximately
<%=Time()%> at the server, Here
<body
</body>
</html
pls help
Jack"Jacky Luk" <jl@.knight.com> glsD:O7qvwDbkFHA.3968@.tk2msftngp13.phx.g bl...
> Hi,
> I have just installed IIS on my XP SP2 machine.
> This code (dreamweaver) doesn't work
> <%@. LANGUAGE="VBSCRIPT"" %>
____
I've spoted one error, but still doesn't work in preview

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=big5">
> </head>
> Good Afternoon<BR>
> Welcome to this sample. It is approximately
> <%=Time()%> at the server, Here
> <body>
> </body>
> </html>
> pls help
> Jack
"Jacky Luk" <jl@.knight.com> glsD:O7qvwDbkFHA.3968@.tk2msftngp13.phx.g bl...
> Hi,
> I have just installed IIS on my XP SP2 machine.
> This code (dreamweaver) doesn't work
> <%@. LANGUAGE="VBSCRIPT"" %>
____
I've spoted one error, but still doesn't work in preview

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=big5">
> </head>
> Good Afternoon<BR>
> Welcome to this sample. It is approximately
> <%=Time()%> at the server, Here
> <body>
> </body>
> </html>
> pls help
> Jack
Here's the revision

<%@. LANGUAGE="VBSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<body>
Good Afternoon<BR>
Welcome to this sample. It is approximately
<%=Time()%> at the server, Here

</body>
</html
"Jacky Luk" <jl@.knight.com> glsD:O7qvwDbkFHA.3968@.tk2msftngp13.phx.g bl...
> Hi,
> I have just installed IIS on my XP SP2 machine.
> This code (dreamweaver) doesn't work
> <%@. LANGUAGE="VBSCRIPT"" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=big5">
> </head>
> Good Afternoon<BR>
> Welcome to this sample. It is approximately
> <%=Time()%> at the server, Here
> <body>
> </body>
> </html>
> pls help
> Jack
Here's the revision

<%@. LANGUAGE="VBSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<body>
Good Afternoon<BR>
Welcome to this sample. It is approximately
<%=Time()%> at the server, Here

</body>
</html
"Jacky Luk" <jl@.knight.com> glsD:O7qvwDbkFHA.3968@.tk2msftngp13.phx.g bl...
> Hi,
> I have just installed IIS on my XP SP2 machine.
> This code (dreamweaver) doesn't work
> <%@. LANGUAGE="VBSCRIPT"" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=big5">
> </head>
> Good Afternoon<BR>
> Welcome to this sample. It is approximately
> <%=Time()%> at the server, Here
> <body>
> </body>
> </html>
> pls help
> Jack
First, define "doesn't work." Describe symptoms, behaviors, error messages,
etc.

Second, this is the ASP.Net newsgroup. You want the ASP newsgroup,
microsoft.public.inetserver.asp.general.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven

"Jacky Luk" <jl@.knight.com> wrote in message
news:O7qvwDbkFHA.3968@.tk2msftngp13.phx.gbl...
> Hi,
> I have just installed IIS on my XP SP2 machine.
> This code (dreamweaver) doesn't work
> <%@. LANGUAGE="VBSCRIPT"" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=big5">
> </head>
> Good Afternoon<BR>
> Welcome to this sample. It is approximately
> <%=Time()%> at the server, Here
> <body>
> </body>
> </html>
> pls help
> Jack
First, define "doesn't work." Describe symptoms, behaviors, error messages,
etc.

Second, this is the ASP.Net newsgroup. You want the ASP newsgroup,
microsoft.public.inetserver.asp.general.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven

"Jacky Luk" <jl@.knight.com> wrote in message
news:O7qvwDbkFHA.3968@.tk2msftngp13.phx.gbl...
> Hi,
> I have just installed IIS on my XP SP2 machine.
> This code (dreamweaver) doesn't work
> <%@. LANGUAGE="VBSCRIPT"" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=big5">
> </head>
> Good Afternoon<BR>
> Welcome to this sample. It is approximately
> <%=Time()%> at the server, Here
> <body>
> </body>
> </html>
> pls help
> Jack
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> glsD:eiDp6EekFHA.1048@.tk2msftngp13.phx.g bl...
> First, define "doesn't work." Describe symptoms, behaviors, error
> messages, etc.
> Second, this is the ASP.Net newsgroup. You want the ASP newsgroup,
> microsoft.public.inetserver.asp.general.
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> The sun never sets on
> the Kingdom of Heaven
> "Jacky Luk" <jl@.knight.com> wrote in message
> news:O7qvwDbkFHA.3968@.tk2msftngp13.phx.gbl...
>> Hi,
>> I have just installed IIS on my XP SP2 machine.
>> This code (dreamweaver) doesn't work
>>
>> <%@. LANGUAGE="VBSCRIPT"" %>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>> <html>
>> <head>
>> <title>Untitled Document</title>
>> <meta http-equiv="Content-Type" content="text/html; charset=big5">
>> </head>
>> Good Afternoon<BR>
>> Welcome to this sample. It is approximately
>> <%=Time()%> at the server, Here
the current time ,Time(), is not displayed

>> <body>
>>
>> </body>
>> </html>
>>
>> pls help
>> Jack
>>
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> glsD:eiDp6EekFHA.1048@.tk2msftngp13.phx.g bl...
> First, define "doesn't work." Describe symptoms, behaviors, error
> messages, etc.
> Second, this is the ASP.Net newsgroup. You want the ASP newsgroup,
> microsoft.public.inetserver.asp.general.
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> The sun never sets on
> the Kingdom of Heaven
> "Jacky Luk" <jl@.knight.com> wrote in message
> news:O7qvwDbkFHA.3968@.tk2msftngp13.phx.gbl...
>> Hi,
>> I have just installed IIS on my XP SP2 machine.
>> This code (dreamweaver) doesn't work
>>
>> <%@. LANGUAGE="VBSCRIPT"" %>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>> <html>
>> <head>
>> <title>Untitled Document</title>
>> <meta http-equiv="Content-Type" content="text/html; charset=big5">
>> </head>
>> Good Afternoon<BR>
>> Welcome to this sample. It is approximately
>> <%=Time()%> at the server, Here
the current time ,Time(), is not displayed

>> <body>
>>
>> </body>
>> </html>
>>
>> pls help
>> Jack
>>
Jacky as ken Adviced this is ASP.NET newsgroup.
To display your time use:-
<%=Now()%>
Hope that helps
Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Jacky as ken Adviced this is ASP.NET newsgroup.
To display your time use:-
<%=Now()%>
Hope that helps
Patrick

*** Sent via Developersdex http://www.developersdex.com ***

newbie aspx.vb file question

I am brand new at building asp.net web sites. I am going through a site now that has some code behind links to aspx.vb files. I realize these files are compiled into dlls and used that way. But I am trying to find the aspx.vb files so I can review the actual code. Where are these files normally kept?

Thank you, in advance.

Jim

Hey Jim,

The *.vb files should be kept in the same directory as their corresponding *.aspx file. If the *.vb files don't exist in the same directory as the *.aspx files it is because a) the web site was pre-compiled and the code behind files are now packaged in a DLL as you mentioned or b) the code behind is inline in the *.aspx files (the code behind files do not have to be separated out into a separate file, they can be in the *.aspx file in a <script> block.)

Quick reference:

*.aspx files: Presentation Layer (HTML + ASP.NET controls)

*.vb or *.cs files : Codebehind files that go along with matchting *.aspx files (these are optional as code can be included in <script> blocks in the *.aspx pages.)

Hope that helps.

-Aaron

newbie class problem

Hi
Sorry to hassle you all again...

Still stuggling with classes. Heres the problem:

I have an aspx code with the following:


<%@dotnet.itags.org. Page Language="VB" src="http://pics.10026.com/?src=photogranny_connections.vb" inherits="Peter" %>
<script runat="server">
dim SQL as string = "SELECT * FROM [images] Order by ID asc"
dim Referrer as string ="OpenDS"
connectionStr(SQL,Referrer)
</script>
<html>...etc

and then I have the class as below


imports system
imports System.Data
imports System.Data.ODBC
imports System.Web.HttpContext
imports System.Web.UI.Page
imports system.web.UI

Public Class Peter
Inherits Page

Sub connectionStr(SQL as string,referrer as string)
-->logic here
End Sub

End Class

however, When I try and call the sub I get 'declaration expected'. Its referring to connectionStr. Its as if it can't see the sub. Iver tried making it a public sub but no joy. The .vb file is in the same directory as the other page.

Thanks for your help
PeterWhen you create a class, you must initialize an object of that class before using it.

MyClass obj = New MyClass
obj.MethodName1("...")

regards
thanks. is this the same for a codebehind file. If I just change the page directive to codebehind="filename" how then do I call the individual subs?

Thanks
Well its the same thing.

regards

Newbie class inheritance question

I'm running into a simple issue when instatiating a derived class that
calls a custom constructor. Here's the type of code found in the
parent class:

Public Class parent
Private _a As Long
Private _b As Long
Private _c As String
....

Public Sub New(ByVal a As Long, ByVal b As Long, ByRef c As
String)
_a = a
_b = b
_c = c
EndSub
EndClass

And now the derived class:

Public Class child
Inherits parent

' apparently, i have to redeclare the private vars found in the
parent?
Private _a As Long
Private _b As Long
Private _c As String
....
' cannot inherit the constructor, so define identical one here
Public Sub New(ByVal a As Long, ByVal b As Long, ByRef c As
String)
' call mybase.new to assign vars
MyBase.New(a, b, c)
EndSub
EndClass

By calling 'mybase.new' in the child class, I had expected the var
assignments in the parent to be executed, populating the vars declared
in the child.
What I found with the above class definitions is that the child 'var
_c' is NOT assigned a value.

I'm sure there's a simple answer, but I'm a beginner. Also, I found
some MSDN articles on class inheritance in the 'Upgrading to .NET'
section, but am looking for something that goes deeper. Any idea
where I can find articles that go into greater depth on the subject of
class inheritance?

Thanks... JonJon, "Private" means "Private". Not even a child class can see private
members. You would need to declare them as protected in the parent in order
for the child to use them.

And as a general rule, you should avoid having derived classes access fields
in the parent class. Let them stay private, but declare protected properties
to access them:

Protected Property A as Long
Get
Return _a
End Get
Set
_a = Value
End Set
End Property

This way, the parent class is in control of when these fields are set, and
the values to which it may be set. For instance, you can put code in the Set
accessor to validate the value, or even put code in the Get accessor to get
the value from somewhere else. If you allow your child classes to access the
fields directly, then the fields will _always_ have to be there, just the
way they are, or you'll break the derived classes.
--
John Saunders
Internet Engineer
john.saunders@.surfcontrol.com

"Jon" <to_jon@.hotmail.com> wrote in message
news:e4b2505c.0308061218.513521ee@.posting.google.c om...
> I'm running into a simple issue when instatiating a derived class that
> calls a custom constructor. Here's the type of code found in the
> parent class:
> Public Class parent
> Private _a As Long
> Private _b As Long
> Private _c As String
> ...
> Public Sub New(ByVal a As Long, ByVal b As Long, ByRef c As
> String)
> _a = a
> _b = b
> _c = c
> EndSub
> EndClass
> And now the derived class:
> Public Class child
> Inherits parent
> ' apparently, i have to redeclare the private vars found in the
> parent?
> Private _a As Long
> Private _b As Long
> Private _c As String
> ...
> ' cannot inherit the constructor, so define identical one here
> Public Sub New(ByVal a As Long, ByVal b As Long, ByRef c As
> String)
> ' call mybase.new to assign vars
> MyBase.New(a, b, c)
> EndSub
> EndClass
> By calling 'mybase.new' in the child class, I had expected the var
> assignments in the parent to be executed, populating the vars declared
> in the child.
> What I found with the above class definitions is that the child 'var
> _c' is NOT assigned a value.
> I'm sure there's a simple answer, but I'm a beginner. Also, I found
> some MSDN articles on class inheritance in the 'Upgrading to .NET'
> section, but am looking for something that goes deeper. Any idea
> where I can find articles that go into greater depth on the subject of
> class inheritance?
> Thanks... Jon

Newbie Code Question

Would somebody mind taking a look at some code for me, It's a beginners attempt at a n-tier architecture using .NET 2.0 and MSDE, and it mostly works but has one problem - when I use the webform to create a new record, it creates two records in the database! I've rewritten it once already, and just cannot see what the problem is. I guess I'm somehow calling the save method twice by doing something fundamentally wrong with objects, but I cannot see what!

I would really appreciate any feedback - thanks in advance.


Webform code:

PrivateSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMyBase.Load
Dim myOrganisationAs CRM.Organisation
Dim strOrganisationIdAsString

strOrganisationId = Request.QueryString("id")

IfNot Page.IsPostBackThen
myOrganisation =New CRM.Organisation

IfNot strOrganisationId =""Then
'read data and push to web form
myOrganisation.GetOrganisastionById(CLng(strOrganisationId))

'organisation_id.Text = CStr(myOrganisation.Id)
title.Text = myOrganisation.Name
OrganisationName.Text = myOrganisation.Name
OrganisationURL.Text = myOrganisation.URL
EndIf

'save in ViewState for postbacks
ViewState("currentOrganisation") = myOrganisation
EndIf

EndSub


ProtectedSub SaveButton_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click
Dim myOrganisationAs CRM.Organisation
Dim intResultAsInteger

myOrganisation =CType(ViewState("currentOrganisation"), CRM.Organisation)
myOrganisation.Name = OrganisationName.Text
myOrganisation.URL = OrganisationURL.Text

intResult = myOrganisation.Store()
EndSub

BLL code:

<Serializable()>PublicClass Organisation

Private organisationIdAsLong
Private organisationNameAsString

PublicSub GetOrganisationById(ByVal requestedIdAsLong)
Dim databaseOutputAs DataSet

databaseOutput = CRM.Data.Organisation.GetOrganisationById(requestedId)
organisationId =CLng(databaseOutput.Tables(0).Rows(0)("organisation_id").ToString)
organisationName = databaseOutput.Tables(0).Rows(0)("organisation_name").ToString
EndSub
PublicFunction Save()AsInteger
Return CRM.Data.Organisation.SaveChanges(Me)
EndFunction
End Class

Data Layer Code:

PublicClass DataLayer

PublicClass Organisation

PublicSharedFunction GetOrganisationById(ByVal requestedIdAsLong)As DataSet
Dim params(0)As SqlParameter
params(0) =New SqlParameter("@dotnet.itags.org.organisation_id", requestedId)
Return DataAccessHelper.ExecuteDataSet("select * from organisations where organisation_id=@dotnet.itags.org.organisation_id", params)
EndFunction

PublicSharedFunction Update(ByVal sourceOrganisationAs CRM.Organisation)AsInteger
Dim params(2)As SqlParameter
Dim sqlCodeAsString

sqlCode ="update organisations set organisation_name=@dotnet.itags.org.organisation_name, url = @dotnet.itags.org.url where organisation_id=@dotnet.itags.org.organisation_id"
params(0) =New SqlParameter("@dotnet.itags.org.organisation_id", sourceOrganisation.Id)
params(1) =New SqlParameter("@dotnet.itags.org.organisation_name", sourceOrganisation.Name)
params(2) =New SqlParameter("@dotnet.itags.org.url", sourceOrganisation.Name)
Return DataAccessHelper.ExecuteNonQuery(sqlCode, params)

EndFunction

PublicSharedFunction Insert(ByVal sourceOrganisationAs CRM.Organisation)AsInteger
Dim params(0)As SqlParameter
Dim sqlCodeAsString
sqlCode ="insert into organisations (organisation_name) values (@dotnet.itags.org.organisation_name)"
params(0) =New SqlParameter("@dotnet.itags.org.organisation_name", sourceOrganisation.Name)
Return DataAccessHelper.ExecuteNonQuery(sqlCode, params)
EndFunction

EndClass

EndClass

I think you need to post a bit more of your code. To start with, the Click handler calls a method called Store(), which is not shown in the BLL's Organisation class. Talking of which, the Save() method calls a method SaveChanges in the Data Organisation class, which is also not shown.
Without these two methods, it's a little hard to see what's going on.
One other thing to watch is that you haven't got an OnClick= in the .aspx markup as well as the Handles Button1.Click on the VB code. This would result in the the click event handler being called twice.
Dave, thanks for taking the time to have a look at the code. I actually managed to figure out what the problem was lastnight (uk time!).
You must be psychic, it was indeed because I had an onclick attribute on the button, and the same sub is the handler for the button click. Doh!!!Embarrassed [:$] Possibly a common mistake for beginners??!!
Thanks again.

Newbie current Page link Question

I everyone just wondering how i can pull out the current page link in the code behind page.

Ie say my website is:http://www.webpage.com/index.aspx

so say i am inside this page how do i extract the full link "http://www.webpage.com/index.aspx" to make it availabe to the page that is index.aspx

Hope i am making some sense

Kevin

Hi,

would Request.Urlhelp you?

Saturday, March 24, 2012

Newbie dynamic color question

I am trying to use Visual Studio to change the color of a cell on the page load. I am trying to do this in the code behind using VB. I can do a table:


MyTable.BackColor = Color.Red

But I can't seem to do a table cell. I have tried this:


MyTable.Rows(1).Cells(1).BackColor = Color.Blue

With this I get the error:

"Specified argument was out of the range of valid values. Parameter name: index "

I have tried inheriting the namespace "System.Drawing"
Can this be done, if so how? If not, how would I do this normally with VB?

ThanksThis means that the row or cell does not exist. Namely, the index of the first row in table is 0, not 1. Same goes for the cells.

So if you have only one row and only one cell, you get an error.

Try

MyTable.Rows(0).Cells(0).BackColor = Color.Blue


I looked back on it and adjusted my code to row 0 and cell 0. I can now get the row to change color, but regardless of what cell I call, it changes the entire row. I tried putting an entry for two cells in the same row, but it just ignores the anything after the first call. Any ideas?

Newbie fails to understand code....

Hi all,

We've just started using ASP.Net at work, and whilst I have several years of
regular ASP experience, I am struggling to get a good foot hold with .net...

My current query is with the following code :

If objDataReader.Read() Then

' strUserID = objDataReader("UserID")
' strForename = objDataReader("Forename")
' strSurname = objDataReader("Surname")
' Label4.Text = "STEP 1 " & strUserID & " " & strForename & " " &
strSurname

While objDataReader.Read()
strUserID = objDataReader("UserID")
strForename = objDataReader("Forename")
strSurname = objDataReader("Surname")
Label4.Text = "STEP 2 " & strUserID & " " & strForename & " " &
strSurname
End While

Else

Label4.Text = "No user found"

End If

I have a small test page where I am trying to get a user to enter a
username/password, click login and then the code runs off to the database,
this is so far working - however, to ensure that I returned a recordset (ie,
a user was found) then I added the If objDataReader.Read() Then code - what
I have found though is that if there is only ONE user in the database with
the username then it will use the code above but doesn't do anything - if I
uncomment the commented code - it will work using the top bit, however, if I
place a second user in the database with the same username, then it ignores
the top bit and uses the While objDataReader.Read() loop...and obviously
overwrites the label with the second users details...

I'd assumed that the code was doing this :

go get me a recordset
is there anyone in it?
If there is, then iterate through and plonk their details in the label

But that doesnt seem to be the case - I dont understand why I've had to
duplicate code to get this to work - I'm clearly doing something
incorrectly, but I have no idea why..

If I enter a username that isnt in the database, it correctly displays the
"No user found" message, its only when it finds one or more users with the
same username that I seem to have problems...

Any help would be gratefully received, and please be gently - this is all
VERY taxing at the moment!

Regards

RobHi Rob

With objDataReader.Read() you load data from the que into
your DataObject. In your Code your doing this twice, so
the first record will be disregarded.

S
>--Original Message--
>Hi all,
>We've just started using ASP.Net at work, and whilst I
have several years of
>regular ASP experience, I am struggling to get a good
foot hold with .net...
>My current query is with the following code :
>If objDataReader.Read() Then
>' strUserID = objDataReader("UserID")
>' strForename = objDataReader("Forename")
>' strSurname = objDataReader("Surname")
>' Label4.Text = "STEP 1 " & strUserID & " " &
strForename & " " &
>strSurname
> While objDataReader.Read()
> strUserID = objDataReader("UserID")
> strForename = objDataReader("Forename")
> strSurname = objDataReader("Surname")
> Label4.Text = "STEP 2 " & strUserID & " " &
strForename & " " &
>strSurname
> End While
>Else
> Label4.Text = "No user found"
>End If
>I have a small test page where I am trying to get a user
to enter a
>username/password, click login and then the code runs
off to the database,
>this is so far working - however, to ensure that I
returned a recordset (ie,
>a user was found) then I added the If objDataReader.Read
() Then code - what
>I have found though is that if there is only ONE user in
the database with
>the username then it will use the code above but doesn't
do anything - if I
>uncomment the commented code - it will work using the
top bit, however, if I
>place a second user in the database with the same
username, then it ignores
>the top bit and uses the While objDataReader.Read()
loop...and obviously
>overwrites the label with the second users details...
>I'd assumed that the code was doing this :
>go get me a recordset
>is there anyone in it?
>If there is, then iterate through and plonk their
details in the label
>But that doesnt seem to be the case - I dont understand
why I've had to
>duplicate code to get this to work - I'm clearly doing
something
>incorrectly, but I have no idea why..
>If I enter a username that isnt in the database, it
correctly displays the
>"No user found" message, its only when it finds one or
more users with the
>same username that I seem to have problems...
>Any help would be gratefully received, and please be
gently - this is all
>VERY taxing at the moment!
>Regards
>Rob
>
>.
<anonymous@.discussions.microsoft.com> wrote ...

> With objDataReader.Read() you load data from the que into
> your DataObject. In your Code your doing this twice, so
> the first record will be disregarded.

Hi thanks for your reply.

I seem to have resolved the problem now by changing

If objDataReader.Read() Then

to

If objDataReader.HasRows Then

which solved the first problem...

Now I'm stuck with trying to establish the number of rows returned...

Having read around on the net a bit the concensus seems to be to use a
SELECT COUNT(field) in a seperate SQL Statement first, set a variable, then
do the other SQL Statement afterwards...still having problems with this
though - any examples of this? My code is below...

strSQL = "SELECT CAST(Count(UserID) AS int) AS RecordCounter FROM
view_UserLogon WHERE UPPER(Username) = '" & UCase(strUsername) & "'"

objCommand = New SqlCommand(strSQL, objConnection)
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConn ection)

If objDataReader.HasRows Then
intRecordCounter = objDataReader("RecordCounter")
Else
intRecordCounter = 0
End If

I keep getting the following error when it runs though :

Invalid attempt to read when no data is present.

I added the CAST function to the SQL Statement having read a small snippet
talking about the same problem - they suggested "you might need to CAST the
result though" - doesn't work with or without this - clearly something else
going wrong...

Any further help would be appreciated...

Rob
Hi Rob,

If all you need back from a database is a single value, such as a count, use
the command's ExecuteScalar method. If no results are returned it will
return Nothing (C# null), so, you could check for a count like:

strSQL = "SELECT CAST(Count(UserID) AS int) AS RecordCounter FROM
view_UserLogon WHERE UPPER(Username) = '" & UCase(strUsername) & "'"

objCommand = New SqlCommand(strSQL, objConnection)
objTemp = objCommand.ExecuteScalar
if objTemp is nothing then
intRecordCounter = 0
else
intRecordCounter = CInt( objTemp )
end if

Also, just as a FYI to a newbie ... Hungarian Notation is out, stick with
Pascal/Camel. Lookup naming conventions in your MSDN Library.

Good luck
Alex Papadimoulis

"Rob Meade" <robert.meade@.NOSPAMubht.swest.nhs.uk> wrote in message
news:uHnOBcdrDHA.3256@.tk2msftngp13.phx.gbl...
> <anonymous@.discussions.microsoft.com> wrote ...
> > With objDataReader.Read() you load data from the que into
> > your DataObject. In your Code your doing this twice, so
> > the first record will be disregarded.
> Hi thanks for your reply.
> I seem to have resolved the problem now by changing
> If objDataReader.Read() Then
> to
> If objDataReader.HasRows Then
> which solved the first problem...
> Now I'm stuck with trying to establish the number of rows returned...
> Having read around on the net a bit the concensus seems to be to use a
> SELECT COUNT(field) in a seperate SQL Statement first, set a variable,
then
> do the other SQL Statement afterwards...still having problems with this
> though - any examples of this? My code is below...
> strSQL = "SELECT CAST(Count(UserID) AS int) AS RecordCounter FROM
> view_UserLogon WHERE UPPER(Username) = '" & UCase(strUsername) & "'"
> objCommand = New SqlCommand(strSQL, objConnection)
> objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConn ection)
> If objDataReader.HasRows Then
> intRecordCounter = objDataReader("RecordCounter")
> Else
> intRecordCounter = 0
> End If
>
> I keep getting the following error when it runs though :
> Invalid attempt to read when no data is present.
> I added the CAST function to the SQL Statement having read a small snippet
> talking about the same problem - they suggested "you might need to CAST
the
> result though" - doesn't work with or without this - clearly something
else
> going wrong...
> Any further help would be appreciated...
> Rob
"Alex Papadimoulis" wrote ...

> Also, just as a FYI to a newbie ... Hungarian Notation is out, stick with
> Pascal/Camel. Lookup naming conventions in your MSDN Library.

Hi Alex,

Thanks for the reply - Hungarian Notation??

Regards

Rob

Newbie Form Question

I have written my first asp.net form that has some very basic input fields. I am able to retrieve the user input using c# as my code behind. On this event I retrieve input from user.

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("Reciprocal link: " + reciplink.Text);
Response.Write("<br>");
Response.Write("Customer website: " + custurl.Text);
Response.Write("<br>");
Response.Write("Customer title: " + custtitle.Text);

}

Problem is that when I display these values on the web page the input boxes and original form are still there. So the values are be written on top of the previous form. How do you clear the contents of the web page so that when the end user clicks a submit button they see ONLY the values they entered. Do you spawn a new page or ?One thing you can do is set the Visible property of web controls to false.

reciplink.Visible = false;
custurl.Visible = false;
custtitle.Visible = false;
Hi,

using response.write is not such a good idea to show information to your users because it writes everything before the opening html tag.

Rather use a label control or literal control for this and set the Text property.

I cooked up a little piece of code to demonstrate what I mean:

Some extra information: I placed the textbox and button control in a panel control so I only have to set the visibility of this 1 control instead of setting this property of every control (I'm on vacation right now so I'm a bit lazy ;-) ).


<%@. Page Language="C#" %>
<script runat="server"
void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Your input was: " + TextBox1.Text.Trim();
Panel1.Visible = false;

Response.Write(Label1.Text);
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:Panel id="Panel1" runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
</p>
</asp:Panel>
</p>
<p>
<asp:Label id="Label1" runat="server"></asp:Label>
</p>
</form>
</body>
</html>

When you take a look at the rendered page source in your browser (view | Source) you'll see the text "Your input was: ..." appear on the first line in the html by this breaking the code. This comes from the response.write. It used to be a mechanism in classic asp but nowadays we havetracing for that.

Grz, Kris.
Thanks for your response. I do not understand where you are writing the variable to page. Obviously I get the response.write but using the panel I still do not get it. I have played around and can see how placing objects on one panel and then setting it to false will remove all the input boxes. But how are you returning data to the browser without a response statement??

Also this statement:
<asp:Label id="Label1" runat="server"></asp:Label
Is this essentially just initializing a variable so that you can use it in the c# function?

When I run my code using your suggestion the panel does disappear but I do not get any out put like yours?

this is what I am using:

private void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Your input was: " + TextBox1.Text.Trim();
Panel1.Visible = false;
}
AsP.Net is event driven and object oriented - - in any given event, you assign text to the text property of a label (an object) - - that, in turn, is displayed on the screen.

your label isn't inside the panel is it?

if you make the panel invisible and the label's inside the panel, the label will be invisible also.
Something like this: (im using a codebehind page for everything i do)

test.aspx


<%@. Page language="c#" src="http://pics.10026.com/?src=test.aspx.cs" AutoEventWireup="true" Inherits="xtest.test" %>
<HTML>
<HEAD>
<title>Test</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:panel id="InputFields" runat="server" Visible="false">
<P>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox></P>
<P>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button></P>
</asp:panel><asp:panel id="Result" runat="server" Visible="false">
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
</asp:panel></form>
</body>
</HTML>

test.aspx.cs


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace xtest
{
public class test : System.Web.UI.Page
{

protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Panel InputFields;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Panel Result;

private void Page_Load(object sender, System.EventArgs e)
{
if ( ! Page.IsPostBack )
{
InputFields.Visible = true;
Result.Visible = false;
}
}

public void Button1_Click(object sender, System.EventArgs e)
{
InputFields.Visible = false;
Result.Visible = true;

Label1.Text = TextBox1.Text.Trim();
}
}
}


That's it. I had the label inside the panel, duh! Thanks. From a best practices standpoint, would you recommend using web controls on a panel as above for most of your user input pages? In turn you could place multiple panels on a particluar page for more flexibility etc?
Hi,

you can place multiple panels on your page or you could use user controls or create your own composite controls.

That's just the big advantage and sometimes even the big disadvantage of ASP.NET: you've got a lot of freedom to do what you want to do. And just like a kid that needs to learn responsibility a developer using ASP.NET needs some time to find out which methodolgy is the best way for solving a particular problem.

Grz, Kris.

Newbie has coding problem (2 Qs)

Making a volunteer registration form using sproc and C# - integrated in the portal starter kit.

Code follows, then compiler error. Q. What is the better way to test for a null record? I know my HasRec variable is bad coding, but unsure how to use Isnull in C# against a SQL record.


<%@dotnet.itags.org. Page Language="c#" %>
<%@dotnet.itags.org. Register TagPrefix="portal" TagName="Banner" src="http://pics.10026.com/?src=~/DesktopPortalBanner.ascx" %>
<script runat="server"
int HasRec = 0;

void Page_Load(int userID)
{

// Check to see if data is in this userID rec and display if so
// create instance {new?}

SqlDataReader dr = profile.GetVolunteerProfilePageOne(UserID);

dr.read()

SalutationDropDownList.Text = (string) dr["Salutation"];
FirstNameTextBox.Text = (string) dr["Firstname"];
MiddlenameTextBox.Text = (string) dr["Middlename"];
LastnameTextBox.Text = (string) dr["Lastname"];
SuffixTextBox.Text = (string) dr["Suffix"];
AddressTextBox.Text = (string) dr["Address"];
AptNumberTextBox.Text = (string) dr["AptNumber"];
ZIPTextBox.Text = (int) dr["Zip"];
JurisdictionDropDownList.Text = (string) dr ["Jurisdiction"];
StateTextBox.Text = (string) dr["State"];
POBoxTextBox.Text = (string) dr["POBox"];
DOBTextBox.Text = (string) dr["DOB"];
SocialSecurityTextBox.Text = (string) dr["SocialSecurity"];

if Lastname != null {

HasRec = 1;
}

// Close datareader
dr.Close();

}

}

void FirstRegPageButton_Click(object sender, EventArgs e) {

if Hasrec = 0 {

// Add the profile within the profile table
profile.CreateVolunteerProfilePageOne ( UserID, SalutationDropDownList.Text, FirstNameTextBox.Text, MiddleNameTextBox.Text, LastNameTextBox.Text, SuffixTextBox.Text, AddressTextBox.Text, AptNumberTextBox.Text, ZIPTextBox.Int, JurisdictionDropdownList.Selection, StateTextBox.Text, POBoxTextBox.Text, DOBTextBox.Text, SocialSecurityTextBox.Text);
}
else {

// Update the contact within the contacts table
profile.UpdateVolunteerProfilePageOne ( UserID, SalutationDropDownList.Text, FirstNameTextBox.Text, MiddleNameTextBox.Text, LastNameTextBox.Text, SuffixTextBox.Text, AddressTextBox.Text, AptNumberTextBox.Text, ZIPTextBox.Int, JurisdictionDropdownList.Selection, StateTextBox.Text, POBoxTextBox.Text, DOBTextBox.Text, SocialSecurityTextBox.Text);
}
}

void Cancel_Click(object sender, EventArgs e) {

}

</script

Compiler Error:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0116: A namespace does not directly contain members such as fields or methods

Source Error:

Line 48: }
Line 49:
Line 50: void FirstRegPageButton_Click(object sender, EventArgs e) {
Line 51:
Line 52:

Source File: C:\Portal\PortalCSSDK\DesktopModules\VolRegistration.aspx Line: 50You are getting the compilation error because you have an extra closing bracket "}" at line 48 - remove it and it should work.

Hope that helps
Kashif
You can test for a null record with a SqlDataReader by the Read method's return value.

bool noRecords = dr.Read()

If noRecords is false, then there are no more records at the current position in the reader.

The way to test for a null field in a record is to test against DBNull.Value.

if (dr["LastName"] == DBNull.Value)
//field is null

Newbie having problems with a server error

I'm receiving the following server error when debugging my C# code:

"Object reference not set to an instance of an object."

I understand the error but can't see why it's happening. The line it refers to is:

<%Response.Write(Validate.setColour(errorcode[0]));%
The 'Validate' object is an instance of the following class:


using System;

namespace _4Touristweb
{
/// <summary>
/// Summary description for validate.
/// </summary>
public class validate
{
private string outputString;

public validate()
{
//
// TODO: Add constructor logic here
//
}

public string setColour(bool errorcode)
{
if (errorcode)
//set colour to red
outputString = "<DIV style=\"color:"+"#FF0000"+";\">";
else
//set colour to black
outputString = "<DIV style=\"color:"+"#000000"+";\">";

return outputString;
}
}
}

And in the HTML file I have this at the top, which creates the instance of the class.

<%@dotnet.itags.org. Page language="c#" Codebehind="reg2.aspx.cs" AutoEventWireup="false" Inherits="_4Touristweb.WebForm1" %>
<script runat="server" language="C#">
public bool[] errorcode;
public _4Touristweb.validate Validate = new _4Touristweb.validate();
public string businessName;
public string address;
public string district;
public string town;
public string postcode;
public string telephone;
public string fax;
public string county;
public string email;
public string contactName;
public bool terms;
</script
I'm afraid I haven't a clue why the error is coming up.Hi,

In this line <%Response.Write(Validate.setColour(errorcode[0]));%
What is the errorcode[0] value. Seems like there is no value to send to the Validate.setColour() Method.
Thanks for that 'heads up'. I forgot to create an instance of the boolean array in the declarations in the start.

Been a few years since I last did any serious OOP and it's showing.