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.

user6875529
  • 101
  • 9
  • 1
    Just a tip, I can help you get it into there with C#... but Jqery/javascript is a much better fit here. – Trey Apr 19 '17 at 18:25
  • Possible duplicate of [how to add a div to container div in c# code behind](http://stackoverflow.com/questions/1165529/how-to-add-a-div-to-container-div-in-c-sharp-code-behind) – Trey Apr 19 '17 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? – user6875529 Apr 19 '17 at 18:27
  • Hint: A `Label` Control is a `
    ` in HTML.
    – VDWWD Apr 19 '17 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: https://forums.asp.net/t/2086468.aspx?Send+data+from+c+to+jquery+in+same+page – Ethilium Apr 19 '17 at 18:35
  • @Trey I edited my code following the instructions from the thread you linked to, will this work? – user6875529 Apr 19 '17 at 18:39
  • @user6875529, I guess another question would be, why are you creating a new div instead of using an existing one? What message are you trying to display? – Ethilium Apr 19 '17 at 18:40
  • and @Ethilium that certainly looks interesting, will have a look at that as well. And to your new question: it's like posting on a forum. – user6875529 Apr 19 '17 at 18:41

0 Answers0