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 5966259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:46:20+00:00 2026-05-22T19:46:20+00:00

i have a div element in my html, <div id=userSolution runat=server text=1234512345123451234512345></div> Yes it

  • 0

i have a div element in my html,

<div id="userSolution" runat="server" text="1234512345123451234512345"></div>

Yes it does contain 25 characters,

i have a button:

<asp:Button id="saveGame" runat="server" text="Save Game" onclick="saveGame_Click" />

server Code:

protected void saveGame_Click(object sender, EventArgs e)
{
    string clientInput = userSolution.Attributes["text"];
}

So why… when i debug, does clientInput = “” ?

By my reckoning… text="1234512345123451234512345"

so string clientInput= userSolution.Attribute["text"]; should work right? :s

confused…

even if the div is:

<div id="userSolution" runat="server">1234512345123451234512345</div>

and i read

string clientId = userSolution.InnerHTML;

Still Fails

  • 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-05-22T19:46:21+00:00Added an answer on May 22, 2026 at 7:46 pm

    You can’t post back the data that way in a div tag if you are setting the value of the div on the client side. You’ll need to use a form element, like a hidden textbox if you want to use a straight ASP.NET postback.

    Here’s a simple example. It uses a javascript event to set the text of a HiddenField when the button is pressed and then displays the text on postback.

    <%@ Page Language="C#" AutoEventWireup="true" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript">
        function copyToHiddenField() {
            var hidden = document.getElementById("<%= txtHidden.ClientID %>");
            var theDivText = document.getElementById("thedata").innerHTML;
            hidden.value = theDivText;
            return true;
        }
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div id="thedata">Here's the data!</div>
            <asp:HiddenField ID="txtHidden" runat="server" />
            <asp:Button ID="btnSumbit" Text="Submit" OnClick="btnSumbit_OnClick" runat="server" />
            <asp:Literal ID="litText" runat="server" />
        </form>
    </body>
    </html>
    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        btnSumbit.Attributes.Add("onclick", "return copyToHiddenField();");
    }
    
    public void btnSumbit_OnClick(object sender, EventArgs e)
    {
        litText.Text = txtHidden.Value;
    }
    </script>
    

    EDIT
    As stated in the answers/comments, you can use the InnerText property of a div tag when runat="server" is specified, but you will only be able read out the InnerText that is set when the page is rendered. Client side updates to the InnerText of the div will not be sent to the server on postback.

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

Sidebar

Related Questions

I want to have the innerHTML of my div element to contain some HTML
I have a div element in an HTML document. I would like to extract
I have the following html: <div id=container> <ul> <li>element 1</li> <li>element 2</li> </ul> </div>
I have a div element containing some text. When the user clicks a word
I have a script block, in the div element which is appended after html
I have a button and a div in my html page. Initially I used
I have a div <div id=maindiv></div> and some checkboxes to add some html element
I have a DIV element with fixed width having some text which doesn't have
I have this html code <div id=mydiv> <div> <span>Text inside span</span> Text next to
I have a div element which has these css attributes : HTML <div class=messageContainer></div>

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.