0

I am trying to get a string returned by a c# function and display it in an html table I have created. I have an asp.net button which calls a c# button_onclick function:

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

I also have an html table:

<table>
<tr>
    <th>Col1</th>
    <th><span>Col2</span></th>
    <th>Col3</th>
</tr>

<tr>
    <td>Random1</td>
    <td>Random2</td>
    <td>Random3</td>
</tr>
</table>

I have a c# function linked to the button click.

protected void Button1_Click(object sender, EventArgs e)
{
  //not sure what to do here. I want to call a separate function which will return
  //an array of 3 strings which would go in place of Random1, Random2, Random3 in the table
}

The reason I'm not using an asp.net table is because I want to use the css for my html table (let me know if there's a way to incorporate that css into an asp.net table, or if my logic is completely off here). Any idea how I should approach this?

0

2 Answers 2

2

One option is to put an asp:Label into your table

<tr>
    <td><asp:label id="lblRandom1" runat="server" /></td>
    <td><asp:label id="lblRandom2" runat="server" /></td>
    <td><asp:label id="lblRandom3" runat="server" /></td>
</tr>

and populate those from within Button1_Click

Also, you can use css with an asp table by setting the CssClass attribute, e.g.

<asp:Table CssClass="classname" runat="server">
Sign up to request clarification or add additional context in comments.

Comments

2

Make your <td> runat server which would make it a HtmlTableCell

<td runat="server" id="td1">Random1</td>
<td runat="server" id="td2">Random2</td>
<td runat="server" id="td3">Random3</td>

So you can access them in your click event:

protected void Button1_Click(object sender, EventArgs e)
{
     td1.InnerText ="Random1";
     td2.InnerText ="Random2";
     td3.InnerText ="Random3";
}

because the HtmlTableCell is subclass of HtmlContainerControl which provides properties to set or get the Innertext and InnerHtml which in turn will be rendered in the <td>

Comments

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.