TiltingCode
Programmer
I am creating some ASP.Net pages using C#. I want to create a class which will be used by other cs files. What I think I want to do is pass the this keyword as a parameter. The reason for this is I want to use .Controls.Add(new LiteralControl in each class using the current cs file. I've tried using ref but I'm definitely doing something wrong.
As simple as possible, here is what I have:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Class1.GenerateHTML();
}
}
And here is the class:
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
public static void GenerateHTML()
{
//this.Controls.Add(new LiteralControl("<table><tr>"));
//this.Controls.Add(new LiteralControl("<td colspan=2 align=center valign=middle >"));
//this.Controls.Add(new LiteralControl("<table><tr><td>"));
//this.Controls.Add(new LiteralControl("<input id='Text1' type='text' value='This is text' />"));
//this.Controls.Add(new LiteralControl("</td><td>"));
//this.Controls.Add(new LiteralControl("<a href=tektips.com>"));
//this.Controls.Add(new LiteralControl("Hi This is someone struggling!"));
//this.Controls.Add(new LiteralControl("</a>"));
//this.Controls.Add(new LiteralControl("</td></tr></table>"));
}
}
The commented code is what I want to execute but of course I want to pass the current cs class. Please note I am learning C# so any additional advice would be greatly appreciated.
As simple as possible, here is what I have:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Class1.GenerateHTML();
}
}
And here is the class:
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
public static void GenerateHTML()
{
//this.Controls.Add(new LiteralControl("<table><tr>"));
//this.Controls.Add(new LiteralControl("<td colspan=2 align=center valign=middle >"));
//this.Controls.Add(new LiteralControl("<table><tr><td>"));
//this.Controls.Add(new LiteralControl("<input id='Text1' type='text' value='This is text' />"));
//this.Controls.Add(new LiteralControl("</td><td>"));
//this.Controls.Add(new LiteralControl("<a href=tektips.com>"));
//this.Controls.Add(new LiteralControl("Hi This is someone struggling!"));
//this.Controls.Add(new LiteralControl("</a>"));
//this.Controls.Add(new LiteralControl("</td></tr></table>"));
}
}
The commented code is what I want to execute but of course I want to pass the current cs class. Please note I am learning C# so any additional advice would be greatly appreciated.