Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2004, 11:31 AM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Alerts

Here is my code:

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

        Dim user As String

        Dim response As String

        Dim msg As String

        Dim myconnection As SqlClient.SqlConnection = New SqlClient.SqlConnection

        myconnection.ConnectionString = "Data Source=WJEVIS;database=WJEVISION;User ID=xx;Password=xxx"

        myconnection.Open()

        Dim comSQL As SqlClient.SqlCommand = New SqlClient.SqlCommand



        'Add code to set CommandText and Connection properties of the command

        'If (txtLogin.Text = "" Or txtLogin.Text = "Please enter something.") Then

        ' txtLogin.Text = "Please enter a valid Login."

        ' Return

        'End If



        comSQL.CommandText = "select username,password from seuser where username = '" & txtLogin.Text & "'"

        comSQL.CommandText = "select * from seuser where username = '" & txtLogin.Text & "'"

        comSQL.Connection = myconnection





        Dim readerSQL As SqlClient.SqlDataReader

        'Add code to execute the command

        readerSQL = comSQL.ExecuteReader()

        user = txtLogin.Text





        'Add code to loop through the records, add each to the listbox

        If readerSQL.HasRows Then

            Do While readerSQL.Read

                'Display in list box

                'lstUsers.Items.Add(readerSQL.Item("username").ToS tring) '& " " & readerSQL.Item("LastName").ToString)

                Dim file As New System.IO.StreamWriter("C:\test.txt", True)

                file.WriteLine("Here is the first line." & " " & user)

                file.Close()

                Server.Transfer("Webform1.aspx")

            Loop

        Else

            Page.RegisterStartupScript("MyScript", _

            "<script language=javascript>" & _

   "function AlertHello() { alert('Please enter the correct username'); }</script>")



            btnLogin.Attributes("onclick") = "AlertHello()"

            txtLogin.Text = ""

            Return



        End If


Renee C. Walker
__________________
Renee C. Walker
 
Old March 3rd, 2004, 02:39 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

as i mean from your words:
i don't think that you could generate online Alerts after checking for any errors in code behind , the code behind only generate the page with it's client scripts and displayed on client side.

if you want this client code to work each time you have to put is at page load event,

note: you can use validators controls to work as client check and also you could use in code behind.

Ahmed Ali
Software Developer
 
Old March 3rd, 2004, 02:49 PM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, thanks.

Renee C. Walker
 
Old March 3rd, 2004, 03:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I agree with alyeng2000 to use Validation Controls.

 
Old March 4th, 2004, 01:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

in order to run JavaScript Alert from ur Code BehindePage:
Code:
string sWindow As = "mywindow";
string jscript;

jscript = "<script language='JavaScript'>mywindow = window.open('file.aspx','" + sWindow + "','height=350,width=532,toolbars=no,resizable=no')</script>";

RegisterClientScriptBlock("mywindow", jscript);
Always:),
Hovik Melkomian.
 
Old March 4th, 2004, 02:17 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Renee,

You're almost entirely correct with what you have. The only problem is with that attribute assignment and the javascript function. You don't need either...try this:

Page.RegisterStartupScript("MyScript", _
    "<script language=javascript>" & _
    "alert('Please enter the correct username');</script>")


Peter
------------------------------------------------------
Work smarter, not harder.
 
Old March 5th, 2004, 10:58 AM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Peter,

I changed my code and it's still working the same way. When I enter the wrong username the first time it does not display the alert. If I enter a wrong username the second time, it does display the alert. But, when I enter the correct username after that, it displays the alert again, but execute the correct procedure after that.

Renee C. Walker
 
Old March 5th, 2004, 09:16 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

That doesn't make sense. You have the alert in the right place. From what you have up there, I can't see why you would get this problem.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old March 8th, 2004, 09:04 AM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, Thanks.

Renee C. Walker





Similar Threads
Thread Thread Starter Forum Replies Last Post
Timed alerts. jpool Visual Basic 2005 Basics 4 June 28th, 2008 09:26 AM
catch the alerts catchrohith Classic ASP Basics 1 October 26th, 2006 06:39 AM
Closing Pages and popup alerts Quick209 ASP.NET 2.0 Basics 0 November 14th, 2005 09:26 PM
Formatting Alerts fs22 Javascript How-To 3 June 9th, 2004 04:15 PM
Using Alerts rwalker ASP.NET 1.0 and 1.1 Basics 2 March 3rd, 2004 11:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.