0

I have created a website with a working registration and login. However, I ran into some trouble when trying to make a little forum. What I want the forum to do is creating a div containing the message when the user filled a textbox and submitted it by clicking on a button.

The question is, how can I add html to my div by just using code? This is what I have already.

protected void Submit_Click(object sender, EventArgs e)
    {
        if (Message.Text != null)
        {
            HtmlGenericControl post = new HtmlGenericControl("div");
            HtmlGenericControl message = new HtmlGenericControl("p");
            message.InnerText = Message.Text;
            post.Controls.Add(message);
        }
        else
        {

        }
    }

Any help or suggestions are appreciated, thank you.

8
  • 1
    Just a tip, I can help you get it into there with C#... but Jqery/javascript is a much better fit here. Commented Apr 19, 2017 at 18:25
  • Possible duplicate of how to add a div to container div in c# code behind Commented Apr 19, 2017 at 18:27
  • Yeah I thought that too, but I'll have to link the user from the database as well, you can't do that with JS can you? Commented Apr 19, 2017 at 18:27
  • Hint: A Label Control is a <div> in HTML. Commented Apr 19, 2017 at 18:29
  • @user6875529, its actually pretty easy to send data to and from js/code behind. Research Jquery AJAX calls. Here is a good example: forums.asp.net/t/… Commented Apr 19, 2017 at 18:35

0

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.