This topic is locked

css group id

3/25/2026 11:26:39
ASPRunner.NET General questions
M
max benelli author

Hi, I would like to make different CSS depending on the group ID of a user.

ChatGPT 3/25/2026

Yes, you can apply different CSS styles based on the user group ID in ASPRunner.NET. You can achieve this by using server-side code to determine the user's group and then dynamically setting the CSS class or styles.

Here’s a general approach to accomplish this:

  1. Determine the User Group ID: You can access the user group information using the built-in functions provided by ASPRunner.NET.


  2. Set a CSS Class or Style Based on Group ID: You can use conditional logic in your ASP.NET code to assign different CSS classes based on the user's group ID.



Here’s a simplified example to illustrate this:

Step 1: Identify User Group

Assuming you have a way to get the current user's group ID, you might have code like this:

// Get the current user's group ID
int userGroupId = GetCurrentUserGroupId(); // Implement this method based on your authentication logic

Step 2: Apply CSS Conditionally

Now, you can use this group ID to apply different CSS classes:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Dynamic CSS Example</title>
<link id="dynamicCss" runat="server" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<!-- Your page content -->
</div>
</form>
</body>
</html>

Code-Behind (C#)

In your code-behind file (Default.aspx.cs), you can set the CSS file dynamically:

protected void Page_Load(object sender, EventArgs e)
{
int userGroupId = GetCurrentUserGroupId(); // Replace this method with your actual logic

// Set CSS based on user group ID
switch (userGroupId)
{
case 1:
dynamicCss.Attributes["href"] = "styles/group1.css";
break;
case 2:
dynamicCss.Attributes["href"] = "styles/group2.css";
break;
default:
dynamicCss.Attributes["href"] = "styles/default.css";
break;
}
}

private int GetCurrentUserGroupId()
{
// Implement logic to retrieve the current user's group ID
// This is just a placeholder
return 1; // Example group ID
}

Explanation

  • The <link> tag with runat="server" allows you to manipulate it in the code-behind.
  • In the Page_Load method, you determine the user's group ID and set the appropriate CSS file accordingly.

CSS Files

Make sure you have the CSS files (group1.css, group2.css, and default.css) created in your project directory.

Conclusion

With this approach, you can dynamically apply different CSS styles based on the user’s group ID in ASPRunner.NET. Modify the logic to fit your specific group IDs and styles as needed.

Sergey Kornilov admin 3/25/2026

You can check how it is implemented in Forum template. The main idea is to use AddCSSFile function in BeforeDisplay event of the page where this functionality need to be added.

Sample syntax:

pageObject.AddCSSFile( MVCFunctions.Concat("include/skins/skin_",XSession.Session["colorscheme"],".css" ));

In this example pre-made CSS files are stored in the skins folder and named skin_blue.css, skin_green.css etc.