Retrieve new value typed from input type text with ASP.NET

I'm having trouble to retreive a input element of text type when this was previously set some C# code, for example:

The HTML element in foo.aspx is defined as:

<input type="text" class="form-control" id="name" runat="server" />

From behind code, foo.aspx.cs, there's something like this:

 protected void Page_Load(object sender, EventArgs e)
 {
    bool has_something = ...;
    if(has_something)
        name.Value = "X";
 }

when has_something is true, now matter if user enter value of Y in the input, when I do something like that (code from foo.aspx.cs too):

  protected void go_Click(object sender, EventArgs e)
        {
            if (!IsValid)
                return;

            string Name = name.Value;
            Debug.WriteLine(string.Format("name = {0}", Name)); //X
       }

Instead of get current value on input id = name, say, I've typed Y, I get old value, as set at Page_Load() time.

What am I missing out? should I use Javascript to set the values? How do I fix this?

Answers


I have edited my original response to correct the answer.

Your code in the Page_Load function is being executed when the page performs a postback upon button click.

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bool has_something = ...;
            if (has_something)
                name.Value = "X";
        }
    }

Need Your Help

The usage of boost::mpl::bind

c++ boost boost-mpl

When I try the mpl::bind function with following test code, I failed to pass compiler in gcc,

Composite increment column

sql-server tsql sql-server-2012 sql-server-2008-r2 database-schema

I have a situation where I need to have a secondary column be incremented by 1, assuming the value of another is the same.