Kevin
Kevin

Reputation: 1240

Visual Web Developer: Adding Text Dynamically

I am designing a web page (in Visual Web Developer) that displays a report in graphical form. Once the graphics are seen some comments need to be appended underneath. This can only be done after the graphics have been rendered since the comments will be based on that output.

I need a way to prompt for comments and display them as an ordered list. I thought I could use a textbox with some buttons and replace these with the ordered list when the "Done" button gets clicked -- ie, the textbox and buttons disappear and in their place is the ordered list of comments.

I have hacked and Googled myself silly but I haven't come up with a solution.

Any advice is appreciated.

Regards.

Upvotes: 1

Views: 107

Answers (2)

Kevin
Kevin

Reputation: 1240

I solved this problem by replacing innerHTML like this:

protected void SubmitMessages()
{
    string[] lines = MessagesTextbox.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
    string output = "<ul>";
    foreach (string message in lines)
    {
        if (!message.Equals(""))
        {
            output += "<li>";
            output += message;
            output += "</li>";
        }
    }
    output += "</ul>";
    messagesDiv.InnerHtml = output;

    //string messagesFileLocation = AppDomain.CurrentDomain.BaseDirectory + "/mesages.xls";
    string messagesFileLocation = "D:\\WebApp\\messages.xml";
    FileStream fs = File.Open(messagesFileLocation, FileMode.Create, FileAccess.Write);
    if (lines.Length != 0)
    {
        using (StreamWriter sw = new StreamWriter(fs))
        {
            sw.WriteLine("<Messages>");
            foreach (string message in lines)
            {
                if (!message.Equals(""))
                {
                    sw.WriteLine("\t<message>" + message + "</message>");
                }
            }
            sw.WriteLine("</Messages>");
        }
    }
}

Upvotes: 0

walther
walther

Reputation: 13600

Have you considered Ajax? Do whatever you need and after that make an ajax request to retrieve the comments as needed.

Upvotes: 1

Related Questions