Noshairwan Farooq
Noshairwan Farooq

Reputation: 101

I cannot access the input text field which is created on page load

I have a link on my page "Forgot Password?" When a user clicks on this link the web page get a data from another page from my database table through AJAX.. i.e "A Security Questions" now on that 2nd page I check for the ID of the user and then show the user an input text field like this.

<pre>
    SqlCommand cmd = new SqlCommand();
        //SQl query and connection code over here....
        StringBuilder br = new StringBuilder();
        SqlDataReader rd = cmd.ExecuteReader();
        if(rd.HasRows)
        {
           while(rd.Read()) 
           {
           br.Append("<input type='text' id='answer'><button id='submit'>Check</button> ");

            }
        }
         PlaceHolder1.Controls.Add(new Literal{Text = br});
    </pre>

Now all this code is in Page_Load I have tried alot of things but i cannot access the answer user types in the this input field which is generated if the user exists. Just need you experts to help me to access this data and store it in some variable.

Upvotes: 1

Views: 38

Answers (1)

user5050189
user5050189

Reputation:

this problem because you can access only server control from code behind(server control have property runat="server"). you have used html control so if you want to access data from code behind use reuat="server" or javascript.

you can also use asp.net control-

private void AddButtons()
{
 // Suspend the form layout and add two buttons.
this.SuspendLayout();
Button buttonOK = new Button();
buttonOK.Location = new Point(10, 10);
buttonOK.Size = new Size(75, 25);
buttonOK.Text = "OK";

this.Controls.Add(buttonOK);
this.ResumeLayout();
}

Upvotes: 1

Related Questions