[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

Why do I get name not declared on the alert?

On my web page, when the user clicks the submit button, I do some validations and if something is invalid, I want to alert the user of the problem.  I am trying to use the code below, but I'm getting a message saying 'name alert is not declared'.  What am I missing?
validate_chkBoxList()
        If valChkBoxList = True Then
            alert("You must check at least one agenda item")
 
        End If

Open in new window

0
mmtcunningham1
Asked:
mmtcunningham1
3 Solutions
 
nmarunCommented:
'Alert' is not a VB.NET command it is a JavaScript keyword. You are doing validation in VB.NET, so you need to display the information in a label control or you can use FieldValidators.
0
 
Praveen VenuCommented:
validate_chkBoxList()
        If valChkBoxList = True Then
          Page.RegisterStartupScript("scr","<script> alert('You must check at least one agenda Item');</script>")
 
        End If
0
 
mmtcunningham1Author Commented:
The page.registerstartupscript is no longer used in asp 2.0.  It was suggested to use clientscript instead.  I put this in my code but the alert box is not showing up.  Any suggestions????
validate_ChkBoxList()
        Dim strMessage As String = "You must check at least one agenda item"
        If valChkBoxList = True Then
            ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script language=JavaScript>alert('" _
                + strMessage + "');</script>")
        End If

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CB_ThirumalaiCommented:
The ClientScript.RegisterStartupScript's parameters has been wrongly specified.  Use this.
ClientScript.RegisterStartupScript(Me.GetType(), "popMsg", "alert('" _
                + strMessage + "');", true)

Open in new window

0
 
mmtcunningham1Author Commented:
I changed it but I'm still not seeing the alert.
0
 
Praveen VenuCommented:
Can you post the code you use now?
0
 
mmtcunningham1Author Commented:
Here's all the code that I'm using right now.  Basically, what I'm trying to do is some validation after the user clicks the submit button.  I have several checkboxes and I want to be sure that the user checks at least one checkbox.  
Would it be possible to do the validation before the user clicks submit????

Public Shared Sub MessageAlert_Create(ByRef thePage As System.Web.UI.Page, ByVal thisType As Type, ByVal strMessage As String, ByVal strKey As String)
        Dim ClientScript As System.Web.UI.ClientScriptManager = thePage.ClientScript
        Dim strScript As String = ("alert('" _
                    + (strMessage + "');"))
        If Not ClientScript.IsStartupScriptRegistered(thisType, strKey) Then
            ClientScript.RegisterStartupScript(thisType, strKey, strScript, True)
        End If
 
 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        validate_ChkBoxList()
        If valChkBoxList = True Then
            Dim pg As System.Web.UI.Page = Me
            MessageAlert_Create(pg, Me.GetType, "You must select at least one agenda item", "Tester")
            Exit Sub
        End If
 
    End Sub
 
Sub validate_ChkBoxList()
        For i = 0 To (chkBoxListAgenda.Items.Count - 1)
            If (chkBoxListAgenda.Items(i).Selected) Then
                valChkBoxList = True
                Exit Sub
            End If
        Next
    End Sub

Open in new window

0
 
Praveen VenuCommented:
you need to check for <> True


 If valChkBoxList <> True Then
            Dim pg As System.Web.UI.Page = Me
            MessageAlert_Create(pg, Me.GetType, "You must select at least one agenda item", "Tester")
            Exit Sub
        End If
0
 
mmtcunningham1Author Commented:
That worked!!!! Thanks.
0
 
Praveen VenuCommented:
PLease mark as solution if it worked for you
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now