需要帮助bootstrap modal asp.net

时间:2012-08-21 09:57:42

标签: jquery asp.net twitter-bootstrap modal-dialog

我在asp.net页面的代码后面有一个if语句,如下所示:

If Session("UserActiv") IsNot Nothing Then
    If Session("UserActiv").ToString() = "N" Then
        ClientScript.RegisterStartupScript(Me.GetType(),
            "Details", "LoadDetails();", True)
    End If
Else
    ClientScript.RegisterStartupScript(Me.GetType(),
        "Details", "LoadDetails();", True)
End If

如果我的会话不是什么,如果它的N然后它运行函数LoadDetails() 如果没有,那么它也会加载该函数,如果Y则不执行任何操作。

然后我在我的主页上有这个功能,唯一的问题是,它每次加载页面时加载功能,如果会话是Y,我检查了上Y / N和更低的y / n问题和所有问题都在UPPER案例中。所以没问题。

我的loadDetails()函数是这样的:

<script language="javascript" type="text/javascript">
    function LoadDetails() {
        myModal.load();
    }

    $(document).ready(function () {

        $("#myModal").modal({
            "backdrop": "static",
            // if true, then the backdrop can be closed with a click
            // if false then there is no backdrop.
            "keyboard": false
        })

});
</script>    

我希望像现在一样加载page_load,但是只有当会话没有或者是N时才会加载。我怎么会这样做呢?

EDIT ................ EDIT ................ EDIT ............ ....编辑................编辑................编辑........... .....编辑................ @RYAN

如果我这样做,会话为N

时没有任何反应
Imports System.Web.Security
Imports System.IO
Imports System.Data
Imports System.Data.OleDb

Partial Class _default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Session("UserActiv") IsNot Nothing Then
        If Session("UserActiv").ToString() = "N" Then
            runJQueryCode("$('#myModal').modal('show');")
        End If
    Else
        runJQueryCode("$('#myModal').modal('show');")
    End If

    If (Not Page.IsPostBack) Then

        Dim htmlString As New StringBuilder()
        ' Has the request been authenticated?
        If Request.IsAuthenticated Then
            ' Display generic identity information.
            ' This is always available, regardless of the type of
            ' authentication.
            htmlString.Append("<h3>Generic User Information</h3>")
            htmlString.Append("<b>name: </b>")
            htmlString.Append(User.Identity.Name)
            htmlString.Append("<br><b>Authenticated With: </b>")
            htmlString.Append(User.Identity.AuthenticationType)
            htmlString.Append("<br><b>User ID: </b>")
            htmlString.Append(Session("UserID"))
            htmlString.Append("<br><br>")
            htmlString.Append(Session("UserActiv"))
        End If
        ' Was forms authentication used?

        If TypeOf User.Identity Is FormsIdentity Then
            ' Get the ticket.
            Dim ticket As FormsAuthenticationTicket = (DirectCast(User.Identity, FormsIdentity)).Ticket
            htmlString.Append("<h3>Ticket User Information</h3>")
            htmlString.Append("<b>Name: </b>")
            htmlString.Append(ticket.Name)
            htmlString.Append("<br><b>Issued at: </b>")
            htmlString.Append(ticket.IssueDate)
            htmlString.Append("<br><b>Expires at: </b>")
            htmlString.Append(ticket.Expiration)
            htmlString.Append("<br><b>Cookie version: </b>")
            htmlString.Append(ticket.Version)
            htmlString.Append("<br><b>Cookie CookiePath: </b>")
            htmlString.Append(ticket.CookiePath)
            htmlString.Append("<br><b>Cookie Expired: </b>")
            htmlString.Append(ticket.Expired)
            htmlString.Append("<br><b>Cookie isPersistent: </b>")
            htmlString.Append(ticket.IsPersistent)
            htmlString.Append("<br><b>User Data: </b>")
            htmlString.Append(ticket.UserData)

            ' Display the information.
            LegendInfo.Text = htmlString.ToString()
        End If

        If User.IsInRole("Manager") Then
            ' Display sensitive material
            Session("userrole") = "Site Manager"
        ElseIf User.IsInRole("Admin") Then
            ' Display sensitive material
            Session("userrole") = "Site Admin"
        ElseIf User.IsInRole("User") Then
            ' Display sensitive material
            Session("userrole") = "Alm. Bruger"
        Else
            ' Display only bland material
        End If
    End If
End Sub

Public Function runJQueryCode(ByVal message As String) As Boolean
    Dim requestSM As ScriptManager = ScriptManager.GetCurrent(Page)
    If requestSM IsNot Nothing AndAlso requestSM.IsInAsyncPostBack Then
        ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(message), True)
    Else
        Page.ClientScript.RegisterClientScriptBlock(GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(message), True)
    End If

    Return True
End Function

Private Function getjQueryCode(ByVal jsCodetoRun As String) As String
    Dim sb As New StringBuilder()
    sb.AppendLine("$(document).ready(function() {")
    sb.AppendLine(jsCodetoRun)
    sb.AppendLine(" });")

    Return sb.ToString()
End Function

'Private Sub cmdSignOut_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSignOut.ServerClick
'FormsAuthentication.SignOut()
'FormsAuthentication.RedirectToLoginPage()
'End Sub
End Class    

1 个答案:

答案 0 :(得分:0)

将以下代码段添加到VB.net代码中:

Public Function runJQueryCode(ByVal message As String) As Boolean
        Dim requestSM As ScriptManager = ScriptManager.GetCurrent(Page)
        If requestSM IsNot Nothing AndAlso requestSM.IsInAsyncPostBack Then
            ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(message), True)
        Else
            Page.ClientScript.RegisterClientScriptBlock(GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(message), True)
        End If

        Return True
    End Function

    Private Function getjQueryCode(ByVal jsCodetoRun As String) As String
        Dim sb As New StringBuilder()
        sb.AppendLine("$(document).ready(function() {")
        sb.AppendLine(jsCodetoRun)
        sb.AppendLine(" });")

        Return sb.ToString()
    End Function

然后使用:

If Session("UserActiv") IsNot Nothing Then
        If Session("UserActiv").ToString() = "N" Then
           runJQueryCode("SUCCESS!modaljquerystuff")
        End If
    Else
        runJQueryCode("FAIL!modaljquerystuff")
End If