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

  • Home
  • SEARCH
  • 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 8280857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:49:56+00:00 2026-06-08T09:49:56+00:00

How would I go about setting a session variable from the click of an

  • 0

How would I go about setting a session variable from the click of an ASP:Button before an AutoPostBack event fires.

Here is what I have right now, but I’m not exactly sure I’m doing this right:

 <asp:Button ID="CommitBTN" runat="server" PostBackUrl="~/MMR_Home.aspx" 
 onclick="CommitBTN_Click" UseSubmitBehavior="true" 
 OnClientClick='<% string temp1 = "true"; Session["ClickedFlag"] = temp1; %>' Text="Commit Changes to Database" />

Would this be the correct way of performing this action or am I going at it completely wrong?

EDIT:

Changed my button tag to this:

 <asp:Button ID="CommitBTN" runat="server" PostBackUrl="~/MMR_Home.aspx" 
 onclick="CommitBTN_Click" OnClientClick="document.getElementById('<%= Hidden.ClientID
  %>').value='1'" UseSubmitBehavior="true" Text="Commit Changes to Database" />

I receive this as my error:

Microsoft JScript runtime error: Unable to set value of the property ‘value’: object is null or undefined

  • 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-08T09:49:58+00:00Added an answer on June 8, 2026 at 9:49 am

    Use this:

    Inside aspx file:

    <form runat="server">
        <asp:Button ID="CommitBTN" runat="server" Text="Button" onclick="CommitBTN_Click" OnClientClick="document.getElementById('HiddenField').value='Ram'"/>
        <asp:HiddenField ID="HiddenField" runat="server" />
    </form>
    

    Or

    <script type="text/javascript">
        function setMyHiddenField(myValue) {
            document.getElementById('HiddenField').value = myValue;
    }
    </script>
    
    <form runat="server">
    <asp:Button ID="CommitBTN" runat="server" Text="Button" onclick="CommitBTN_Click" OnClientClick="setMyHiddenField('Ram')"/>
    <asp:HiddenField ID="HiddenField" runat="server" />
    

    ==================================================================

    Inside aspx.cs file

    protected void CommitBTN_Click(object sender, EventArgs e)
        {
            Session["ClickedFlag"] = HiddenField.Value;
            Response.Write(Session["ClickedFlag"]);
        }
    

    It is easy to replase “Ram” with your value. 😉

    you can change Ram to temp1 easy:

    setMyHiddenField(‘temp1’)

    Or you can call this function on your another control events befor CommitBTN pressed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net application c# that uses session state to store a variable
I have a SplitContainer and was wondering how I would go about setting a
I'm curious to know how I would go about setting up my service to
How would i go about setting up a Tkinter Text widget to do something
How would I go about setting a link to perform certain functions like hide
I have a C struct with about 17 members struct settings currentProfile and would
I was wondering how one would go about developing a website from scratch with
I am setting session time in web config. I also have a javascript for
When I have a specific setting in web.config, say the session state configuration, and
I am looking at the performance suggestions lots of pages have about asp.net. Specifically

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.