Creating URLs in asp.net using both name and ID parameters

test.Controls.Add(GetButton(thisReader["session_id"].ToString(), "Join Session"));

I made a modification to the code above, switching it to:

test.Controls.Add(GetButton(thisReader["session_name"].ToString(), "Join Session"));

The reason for this change was to use the session_name in the URL instead of session_id. However, this caused issues as the results on the next page were not displayed correctly due to session_id not being passed. For more details, please see the original question asp.net url generation.

Response.Redirect("EnterSession.aspx?session=" + e.CommandArgument.ToString());

How can I resolve this problem?

C# portion of entersession.aspx:

public partial class _EnterSession2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {



            SessionID.Value = Request.QueryString["session"];
            // Label2.Text = DateTime.Now.ToString();  
            if (User.Identity.IsAuthenticated)
            {
                string userName = User.Identity.Name;
                //Username.Value = User.Identity.Name;
                Username.Value = userName.ToLower();
                HiddenField1.Value = User.Identity.Name;
            }

        }

Answer №1

One approach is to create a custom method in the EnterSession.aspx page that takes Request["session"] as a parameter. This method can then be used to retrieve the session_id from the database based on the session_name.

Here's an example of how you can achieve this:

public partial class _EnterSession2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        SessionID.Value = GetSesssionID(Request["session"]);
        
        if (User.Identity.IsAuthenticated)
        {
            string userName = User.Identity.Name;
            
            Username.Value = userName.ToLower();
            HiddenField1.Value = User.Identity.Name;
        }

    }

private string GetSesssionID(string session_name)
{
    string strRetval = string.Empty;
    
    // Perform a database query here to fetch the session_id and store it in strRetval.

    return strRetval;

}

I hope this solution proves useful for your situation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The function d3.json() does not support googleoverlay

As a newcomer to coding, I am currently working on incorporating the code found at https://bl.ocks.org/mbostock/899711. Instead of using a local .json file, I have opted to read JSON data from a URL. However, I encountered an issue where the LAT and LONG v ...

Tips for converting a raw SQL query to Knex syntax

Recently delving into the world of development, I've come across knex for the first time. Issue: I have a raw SQL query that is functioning correctly. Now, I'm attempting to utilize knex for this query. To better understand how things operate, I ...

Hold off on running addThis

My website utilizes Google Maps along with my own JavaScript functions. Additionally, I am integrating the AddThis JavaScript for social sharing buttons. For optimal performance, I need both my custom JavaScript and Google's JavaScript to load and exe ...

Error: Attempting to access the 'state' property of an undefined variable within the bootstrap framework

While attempting to update the state value, I encountered an error stating TypeError: Cannot read property 'state' of undefined. This error occurs when I enter something in a field and then click submit. As a newcomer to React, I realize this may ...

Convert JSON data into an HTML table using JavaScript without displaying the final result

I need help troubleshooting my JavaScript code that is supposed to populate an HTML table with data from a JSON file. However, the table remains empty and I can't figure out why. Sample JSON Data [{"User_Name":"John Doe","score":"10","team":"1"}, { ...

How would you go about creating a VueJS component that displays a table with a set number of columns and automatically distributes the cells within them?

Hey there! I'm currently working with a VueJS component that looks like this: <template> <div> <table> <tbody> <tr v-for="(item, index) in items" :key="index"> <t ...

Invoke the action method in an MVC controller from a method in a WCF service

In the midst of my MVC project work, I encountered a dependency on a service that must be executed at specific time intervals. This WCF service project is separate from my MVC project, but I successfully integrated it thus far. However, challenges arose w ...

Update a median in MongoDB

I am attempting to create a cache of the mean order in order to prevent retrieving all ratings and avoid aggregation (since the mean needs to be frequently obtained): Here is my proposed solution: Product.findOneAndUpdate({_id: id}, {$inc : {rating_count ...

Modify the innerHTML to adjust font size when a button is clicked in Ionic 5, or eliminate any unnecessary spaces

I have been experimenting with changing the font size of a variable in .html when the variable contains whitespace. In my .ts page, I use the following code to remove the whitespace: this.contents = this.sanitizer.bypassSecurityTrustHtml(this.product[&apos ...

"Help! I'm facing an issue with my PHP PDO insert statement

I've been working on developing a web application that allows users to create new projects, but I've hit a roadblock. For the past couple of days, I've been stuck on a particular issue related to the "New Project" button. When this button i ...

After upgrading from Vuetify version 1.5 to 2.0.18, an issue arises with modules not being found

I encountered the following error: module not found error To address this issue, I took the following steps: Commented out import 'vuetify/src/stylus/main.styl' in the src/plugins/vuetify.js file. Added import 'vuetify/src/styles/main. ...

Tips on retrieving a value nested within 3 layers in Angular

In my Angular application, I have three components - A, B, and C. Component A serves as the main component, Component B is a smaller section nested inside A, and Component C represents a modal dialog. The template code for Component A looks something like ...

AJAX.NET handler for managing hidden field values

I need to update the value of a hidden field control within an AJAX initialize request handler. However, when the page is posted back to the server, the hidden field always retains the previous value. It seems that the viewstate is being processed before I ...

Eliminate any undefined data in the popup map of Javascript

I am working with JSON data that is being displayed in a pop-up on a map. In cases where there is missing data (Visibility), the word undefined appears in the pop-up. Is there a way to remove the undefined text so that it does not show up in the pop-up? ...

When ng-model is updated, form radio buttons trigger memories from the past, causing ng-check to malfunction

Angular 1.* Here is the code snippet: <div class="filter-column"> <div class="filter-title">Market</div> <div class="bottom-line"></div> <div class="overflow-container"> <input type="radio" val ...

Enhancing nested return efficiency

Consider the following two JavaScript functions: function (){ return _.includes(someLongArray, value) && someSimpleValue; } VS function (){ return someSimpleValue && _.includes(someLongArray, value); } Which function will have bett ...

The implementation of async await within a switch case statement is failing to function properly

Is it possible to wait for the resolution of a promise within a switch case statement by using the keyword await? I am facing an issue with my Angular component where the following code is causing crashes in my application. switch (this.status) { ...

Ensuring W3C compliance with form elements on the server-side

After running a website HTML validation on w3.org, I encountered the following error: Bad value for the attribute 'action' on the form element: It must be non-empty. My form is an ASP.NET server-side form and I am unable to set the 'acti ...

Dispensing guarantees with Protractor

q library offers a unique feature that allows resolving and spreading multiple promises into separate arguments: If you have a promise for an array, you can utilize spread instead of then. The spread function distributes the values as arguments in the f ...

Warning in Vue 3: Production is being disrupted by "tags with side effects"

After recently upgrading from Vue 2 to Vue 3, I encountered a problem in my app where certain parts show a warning in development mode: [Vue warn]: Template compilation error: Tags with side effect (<script> and <style>) are ignored in client ...