admin管理员组

文章数量:1291174

How to use Java script alert msg in code behind? This message will be display after save the data.

Here is my code,

enter code here

 Protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Add.Click
    'add new class
    Dim DbClassMst = New ClassMst()
    Dim dsClass As DataSet
    Dim status As Integer = 0
    Dim ResourceObject As Object

    ' 画面リソース定義
    If SessionCtl.GetSession("RES_LANG").ToString = ResourceBase.LOCALE_JA Then
        ResourceObject = New ResourceJa(SessionCtl.GetSession("RES_LANG"))
    Else
        ResourceObject = New ResourceEn(SessionCtl.GetSession("RES_LANG"))
    End If

    If NewClass.Text = "" Then

        lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_REG)
        Exit Sub
    Else
        'check to allow unique class
        dsClass = DbClassMst.DisplayClass1(NewClass.Text)
        If Trim(dsClass.Tables(0).Rows.Count > 0) Then
            status = 1
        End If
        If dsClass.Tables(0).Rows.Count < 10 Then
            If status = 0 Then
                'insert class
                DbClassMst.InsertClassNew(NewClass.Text, dsClass.Tables(0).Rows.Count + 1)
                PopulateClassName()
                NewClass.Text = ""


                Dim AlertMsg As String = ""
                AlertMsg = "<script language='javascript'>alert('Data has been saved');</script>"

                 *********Here I need alert msg.



            Else
                lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_EXIST)
                Exit Sub
            End If

        Else
            lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_MAX)
        End If
    End If

End Sub

but is not working. give me an idea.

How to use Java script alert msg in code behind? This message will be display after save the data.

Here is my code,

enter code here

 Protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Add.Click
    'add new class
    Dim DbClassMst = New ClassMst()
    Dim dsClass As DataSet
    Dim status As Integer = 0
    Dim ResourceObject As Object

    ' 画面リソース定義
    If SessionCtl.GetSession("RES_LANG").ToString = ResourceBase.LOCALE_JA Then
        ResourceObject = New ResourceJa(SessionCtl.GetSession("RES_LANG"))
    Else
        ResourceObject = New ResourceEn(SessionCtl.GetSession("RES_LANG"))
    End If

    If NewClass.Text = "" Then

        lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_REG)
        Exit Sub
    Else
        'check to allow unique class
        dsClass = DbClassMst.DisplayClass1(NewClass.Text)
        If Trim(dsClass.Tables(0).Rows.Count > 0) Then
            status = 1
        End If
        If dsClass.Tables(0).Rows.Count < 10 Then
            If status = 0 Then
                'insert class
                DbClassMst.InsertClassNew(NewClass.Text, dsClass.Tables(0).Rows.Count + 1)
                PopulateClassName()
                NewClass.Text = ""


                Dim AlertMsg As String = ""
                AlertMsg = "<script language='javascript'>alert('Data has been saved');</script>"

                 *********Here I need alert msg.



            Else
                lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_EXIST)
                Exit Sub
            End If

        Else
            lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_MAX)
        End If
    End If

End Sub

but is not working. give me an idea.

Share Improve this question edited Sep 26, 2009 at 9:05 VJS asked Sep 26, 2009 at 8:34 VJSVJS 1,1514 gold badges11 silver badges20 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 6

A better way to do this is to have this as a utility method in a mon class:

Friend Module MyUtilities
    Public Sub Alert(ByVal page As Page, ByVal message As String)
        Dim alertMessage As String = "alert('" & message & "');"
        page.ClientScript.RegisterStartupScript(page.[GetType](), "showAlert", alertMessage, True)
    End Sub
End Module

This can be used in a page like this:

 MyUtilities.Alert(Me, "Sample alert!!!!!")

Your code looks so simpler. Hope this helps!

You should register this script to your page, so this script will be sent to the client.

Page.ClientScript.RegisterStartupScript(typeof(YourPage), 
     "myScripts", 
     "<script language='javascript'>alert('Data has been saved');</script>");

Dim someScript As String = "" someScript = "alert('Your Leave request has been registered');" Page.ClientScript.RegisterStartupScript(Me.GetType(), "onload", someScript)

本文标签: javascriptJava script alert msg in code behind Aspnet 35Stack Overflow