ASP.NET Web Forms, Something equivalent or similar

2019-08-09 05:29发布

问题:

I'm moving over a simple text manipulator program in C# to ASP.NET Web Forms.

I have found that "asp:Label"s can be changed from the code behind, I can't find a list of other "asp:?things?" to use like textbox or textarea etc. I have tried but they are not valid for asp.

Trying to do multiple lines for a Label I don't think is possible. So is there another "asp:" that can act like a console or show multiple lines? Or can you do multiple lines with a Label?

WebPage.aspx

<asp:Label runat="server" id="Label1"></asp:Label>

CodeBehind for WebPage.aspx

Label1.Text = ("My text I wanto change or add etc.");

My problem: My C# code requires adding multiple lines, I don't think this can be done with Labels it will only show the last output in the array.

protected void ShowRawData(string[] rawData)
{
    for (int i = 0; i < rawData.Length; ++i)
        // Console.WriteLine(rawData[i])
        Label1.Text = (rawData[i]);
}

How can I show all the lines in the array with ASP.NET and Web Forms?

回答1:

You can use a Textbox with these properties set:

<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" ReadOnly="True" ></asp:TextBox>

For showing all lines of the array:

protected void ShowRawData(string[] rawData)
{
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < rawData.Length; ++i)
    {
        sb.AppendLine(rawData[i]);
    }
    TextBox1.Text = sb.ToString();
}