Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:03:47+00:00 2026-06-10T07:03:47+00:00

I have an if statement in the code behind for an asp.net page, like

  • 0

I have an if statement in the code behind for an asp.net page, like this:

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

If my session is not nothing, and if its N then it run the function LoadDetails()
If nothing then it also load the function, and if Y then do nothing.

Then I have the function on my main page, my only problem is, that it load the function every time I load the page, also if the session is Y, i have checked for upper Y/N and lower y/n issues and all is in UPPER case. so no problem there.

My loadDetails() function is like this:

<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>    

I’d like this to load at page_load like now, BUT only if the session is nothing or if its N. How would I go about this?

EDIT…………….EDIT…………….EDIT…………….EDIT…………….EDIT…………….EDIT…………….EDIT…………….
@RYAN

if i do it like this, nothing happens when the session is 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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:03:48+00:00Added an answer on June 10, 2026 at 7:03 am

    Add the following sections of code to your VB.net code:

    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
    

    Then use:

    If Session("UserActiv") IsNot Nothing Then
            If Session("UserActiv").ToString() = "N" Then
               runJQueryCode("SUCCESS!modaljquerystuff")
            End If
        Else
            runJQueryCode("FAIL!modaljquerystuff")
    End If     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the past I have always worked from the code behind page in ASP.NET
I have an asp.net application with a c# code-behind, connected to an SQL db
I have a search form that looks like this: The code behind the form
I have a using statement defined like this in codebehind: using Name = Extremely.Long.And.Unwieldy.Namespace
I have kept hearing this statement. Switch..Case is Evil for code maintenance, but it
I have a question regarding applying a RTRIM on a ASP:Hyperlink statement. The code
We have a very simple ASP.Net page for uploading a file to our webserver.
I have one aspx code behind page, that uses a process (p) to call
I wish to have an If statement in my code, which tests if any
I have the following code with a bool if statement inside and in another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.