0

How can I make this button

 resultsHtml.Append(" <button runat="server" ID='btnHelloWorld' OnClick='btnHelloWorld_Click' Text='Upd`ate label!' /> ");

run this

 protected void btnHelloWorld_Click(object sender, EventArgs e)
    {
        lblHelloWorld.Text = "Hello, world";
    }

In the same page? They are both in the back code and the same page. The reason I put it in resultsHtml.Append(); is because it's in the datatable

2
  • when you adding a new button within resultsHtml, does it generate the btnHelloWorld_Click button or not? Commented Jan 24, 2017 at 4:10
  • it generates a button, but it doesn't fire the onClick event. it doesnt even read the CSS Commented Jan 27, 2017 at 7:30

1 Answer 1

1

Dont take whole button HTML script from database. Just take button name and onClick event name from database.

Then create button dynamically from code behind as follow:

    Button btnHelloWorld= new Button();
    btnHelloWorld.ID = "btnEdit";
    btnHelloWorld.Text = "Edit";
    btnHelloWorld.Click += new EventHandler(btnHelloWorld_Click);
    form1.Controls.Add(btnHelloWorld);
Sign up to request clarification or add additional context in comments.

1 Comment

Actually it's not from the database, the data preceding the button is from the database. I just don't know how to cast it in the front end so every entry has that button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.