简体   繁体   中英

Displaying message using VB.Net on ASPX

When a user logs in on my webapp, we need to check the database for unread messages. When there are unread messages, we need to display those messages in an alert. Can anyone help me?

I've tried this:

Response.Write("<script language=""javascript"">alert('Congratulations!');</script>")

And this :

Private Sub Login(ByVal user As String, ByVal password As String)
        Dim loginModel As New LoginModel
        Dim remoteAddr As String = ""
        Try
            remoteAddr = GetIPClient()
            Select Case loginModel.Login(user, password, remoteAddr)
                Case loginModel.LoginResult.login_OK
                    Session("WebUser") = loginModel.WebUser
                    Session("WebUserId") = loginModel.WebUser.WebUserID
                    Master.SetWebUser(Me, loginModel.WebUser)
                    If (CheckIPRange() = True) Then
                        FormsAuthentication.RedirectFromLoginPage(user, False)
                        CheckPasswordValidity()
                    Else
                        ErrorLabel.Text += "<BR>" + _xmlLanguage("wrongip")
                        Utility.Web.SetFocus(Page, PasswordTextbox)
                    End If

                    Dim message As String = "Order Placed Successfully."
                    Dim sb As New System.Text.StringBuilder()
                    sb.Append("<script type = 'text/javascript'>")
                    sb.Append("window.onload=function(){")
                    sb.Append("alert('")
                    sb.Append(message)
                    sb.Append("')};")
                    sb.Append("</script>")

                    ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", sb.ToString())
                Case loginModel.LoginResult.login_Lock
                    Response.Redirect("accessLock.htm")
                Case loginModel.LoginResult.login_Failed
                    ErrorLabel.Text = _xmlLanguage("loginfailed")
            End Select
        Catch exception As Exception
            ErrorLabel.Text = exception.Message
        Finally
            If ErrorLabel.Text.Length > 0 Then ErrorLabel.Visible = True
            loginModel.Dispose()
        End Try
    End Sub

Ok seems there was another problem that was affecting my code. I solved that problem now. So I get my confirmation-box.

Now I would like to capture the click on the "OK"-button, so I can do some work in the codebehind. I would like to call a Sub called "ConfirmMessage". how can i do that?

Add a ScriptManager control to your page inside the form tag (form must be having runat="server")

and afterwards you can call any javascript method like this way

ScriptManager.RegisterStartupScript(this,GetType(),"MethodName","Method()",true);

in your case you can do like this.

ScriptManager.RegisterStartupScript(this,GetType(),"Alert","alert('Congratulations')",true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM