Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
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 June 5th, 2005, 11:03 PM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default another ques regarding Javascript messagebox

Hi, Is it a must to call the function that pop up javascript messagebox in page load? my situation is like this, i hv a new user registration page. whenever user click Register button, the messagebox "Registration is successful" should only be displayed for new user registration.

Now the problem is, even though I enter the user id that is already exist in the database, it still displayed the above messagebox, followed by this message "Sorry, the User ID already exists. Please try again.".

Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        btnRegister.Attributes.Add("onclick", "register();")
    End Sub

    Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
        Dim con As New SqlConnection("data source=localhost; initial catalog=""E-Library Records""; user id=sa")
        Dim str = "SELECT * FROM [UserAccount] WHERE User_id = '" & txtUserID.Text & "'"
        Dim dr As SqlDataReader
        Dim SqlDataAdapter1 As New SqlDataAdapter
        Dim sSQL As New SqlCommand

        With sSQL
            sSQL.Connection = con
            sSQL.Connection.Open()
            sSQL.CommandText = str
            sSQL.CommandType = CommandType.Text
            dr = sSQL.ExecuteReader()
        End With

        Dim User_id, UserID, User_Password, Pwd, str1 As String
        Dim FirstTime, Admin As RadioButton

        If dr.HasRows Then
            Response.Write("Sorry, the User ID already exists. Please try again.")
        Else
            User_id = txtUserID.Text
            User_Password = txtPwd.Text
            User_id = User_id.Trim
            User_Password = User_Password.Trim

            If User_Password.Length < 4 Or User_Password.Length > 10 Then
                Response.Write("Password must be 4-10 characters!")
            End If
            Try
                dr.Close()

                str1 = "INSERT INTO UserAccount Values (@User_id," _
                                        & "@User_Password, @IsFirstTime, @IsAdministrator)"
                Dim InsCom As New SqlCommand(str1, con)
                SqlDataAdapter1.InsertCommand = InsCom
                SqlDataAdapter1.InsertCommand.Parameters.Add(New _
                  SqlParameter("@User_id", SqlDbType.Char, 10))
                SqlDataAdapter1.InsertCommand.Parameters.Add(New _
                  SqlParameter("@User_Password", SqlDbType.Char, 10))
                SqlDataAdapter1.InsertCommand.Parameters.Add(New _
                  SqlParameter("@IsFirstTime", SqlDbType.Char, 1))
                SqlDataAdapter1.InsertCommand.Parameters.Add(New _
                  SqlParameter("@IsAdministrator", SqlDbType.Char, 1))
                SqlDataAdapter1.InsertCommand.Parameters("@User_id").Value = txtUserID.Text
                SqlDataAdapter1.InsertCommand.Parameters("@User_Password").Value = txtPwd.Text
                SqlDataAdapter1.InsertCommand.Parameters("@IsFirstTime").Value = RadioButtonList1.SelectedValue
                SqlDataAdapter1.InsertCommand.Parameters("@IsAdministrator").Value = RadioButtonList2.SelectedValue

                SqlDataAdapter1.InsertCommand.ExecuteNonQuery()

            Catch ex As Exception
                Dim a As String
                a = ex.Message

            Finally
                con.Close()
                Response.Redirect("Admin.aspx")
            End Try
        End If

    End Sub
Anybody can help? Thanks!

Irene

 
Old June 6th, 2005, 05:32 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are calling the register() client-side script on the click
of the Register button. So as soon as you click the register
button, the registration successful message is displayed.
You should be writing the code to display an alert in the
else part after :
SqlDataAdapter1.InsertCommand.ExecuteNonQuery()

response.write("<script language=javascript>alert('Registration successful');</script>")





 
Old June 6th, 2005, 06:11 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried as what u said, but the msgBox is not displayed.

I deleted the code in html head n the page load.n put the code after
SqlDataAdapter1.InsertCommand.ExecuteNonQuery()


Code:
 If User_Password.Length < 4 Or User_Password.Length > 10 Then
                Response.Write("Password must be 4-10 characters!")
            Else
                Try
                    dr.Close()

                    str1 = "INSERT INTO UserAccount Values (@User_id," _
                                            & "@User_Password, @IsFirstTime, @IsAdministrator)"
                    Dim InsCom As New SqlCommand(str1, con)
                    SqlDataAdapter1.InsertCommand = InsCom
                    SqlDataAdapter1.InsertCommand.Parameters.Add(New _
                      SqlParameter("@User_id", SqlDbType.Char, 10))
                    SqlDataAdapter1.InsertCommand.Parameters.Add(New _
                      SqlParameter("@User_Password", SqlDbType.Char, 10))
                    SqlDataAdapter1.InsertCommand.Parameters.Add(New _
                      SqlParameter("@IsFirstTime", SqlDbType.Char, 1))
                    SqlDataAdapter1.InsertCommand.Parameters.Add(New _
                      SqlParameter("@IsAdministrator", SqlDbType.Char, 1))
                    SqlDataAdapter1.InsertCommand.Parameters("@User_id").Value = txtUserID.Text
                    SqlDataAdapter1.InsertCommand.Parameters("@User_Password").Value = txtPwd.Text
                    SqlDataAdapter1.InsertCommand.Parameters("@IsFirstTime").Value = RadioButtonList1.SelectedValue
                    SqlDataAdapter1.InsertCommand.Parameters("@IsAdministrator").Value = RadioButtonList2.SelectedValue

                    SqlDataAdapter1.InsertCommand.ExecuteNonQuery()
                    Response.Write("<script language=javascript>alert('Registration successful');</script>")

                Catch ex As Exception
                    Dim a As String
                    a = ex.Message

                Finally
                    con.Close()
                    Response.Redirect("Admin.aspx")
                End Try
            End If
Do I put the code u suggested in the right place? Thanks!

 
Old June 6th, 2005, 06:59 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The alert is not getting displayed as your page is getting redirected.
Either comment the line:
        Response.Redirect("Admin.aspx")
or you can write the alert line in the Admin.aspx


 
Old June 7th, 2005, 12:47 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If i write the alert line in the Page Load, in Admin.aspx, it works. But in my application,
not only this page getting redirected, i also set some other pages to be redirected to admin.aspx.

If i write it in Admin.aspx, everytime admin page is loaded, the msgBox will be displayed.



 
Old June 7th, 2005, 01:06 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

You have two method to attain this,

1) This is solving the issue in prevois posts by using a querystring value to show your message box if required.
 ie, this page passes "msg=yes" and others "msg=no" (This is easier)

2)You can show an message box and then create a javascript postback using to a hidden linkbutton buttons click event and then redirecting

Prashant


 
Old June 7th, 2005, 01:10 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Wait you have one more choise,
1)You can have generalised message page with 2 params (the message & the redrection page)
2) Page will show the message in a label
2) Then automaticaly redirect to the required page

Prashant






Similar Threads
Thread Thread Starter Forum Replies Last Post
SAXON Ques dev.user06 XSLT 4 July 26th, 2006 10:44 AM
MessageBox using Javascript hoailing22 ASP.NET 1.0 and 1.1 Basics 4 June 7th, 2005 01:40 AM
Rephrase of my ques Regornil JSP Basics 1 July 25th, 2004 09:24 PM





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