locked
setting session in a sample.HTML page RRS feed

  • Question

  • User-1246222823 posted

    Hi all,

    I have developed a project including many pages. But the initial page is HTML , not an aspx page. I want to set the session("language") at this page first. (user can change the language later in the forms)

    Can i set or read the session variables in HTML code???

    Thank you for all helps...

     

    Tuesday, February 22, 2011 5:18 PM

Answers

  • User1415119982 posted

    Can i set or read the session variables in HTML code???

    No you cannot set the session variable in HTML code but you can achieve that with the help of an aspx page. Here's a small sample for you.

    //html page

    <body>
    <form id="myform" action="Default.aspx" method="post">
      //note the action part in the form. This lets you post back to this page.  
    <select id="language" name="language">
    <option value="nepali">Nepali</option>
    <option value="english">English</option>
    
    </select>
    <input type="submit" value="change language" />
    </form>
    </body>



    //default.aspx.cs file

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                  
                    if (Request.Form["language"] != null)
                          session["language"]= Request.Form["language"];
     //to get the form value submitted by the browser you can use request object's form collection
    .
    
                }
    }
    

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 22, 2011 11:14 PM

All replies

  • User1415119982 posted

    Can i set or read the session variables in HTML code???

    No you cannot set the session variable in HTML code but you can achieve that with the help of an aspx page. Here's a small sample for you.

    //html page

    <body>
    <form id="myform" action="Default.aspx" method="post">
      //note the action part in the form. This lets you post back to this page.  
    <select id="language" name="language">
    <option value="nepali">Nepali</option>
    <option value="english">English</option>
    
    </select>
    <input type="submit" value="change language" />
    </form>
    </body>



    //default.aspx.cs file

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                  
                    if (Request.Form["language"] != null)
                          session["language"]= Request.Form["language"];
     //to get the form value submitted by the browser you can use request object's form collection
    .
    
                }
    }
    

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 22, 2011 11:14 PM
  • User712082397 posted

    It cannot be done in HTML page. I would suggest that you convert it to ASPX (should not be a big lift) and then do it.

    Wednesday, February 23, 2011 12:05 PM