drewpecunia
New member
As an exercise in learning I am trying to put all the code for a page in .cs and then compile it to a dll. Then I call that dll from the bin directory into an aspx page.
I can get my cs to compile but on return my page is blank. I think there might be something wrong with my .cs file--but can not see anything right off. Can any of you see where I might be off a little. (ok-well with my code)
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace myPage
{
public class myPage:Control
{
protected System.Web.UI.WebControls.TextBox txtTextBox;
protected System.Web.UI.WebControls.Label lblLabel;
public void CreateChildControls(HtmlTextWriter stringWriter)
{
// Use htmlWriter to write HTML.
string strOpenHTML;
strOpenHTML = "<html><head><title>My Page</title></head>";
strOpenHTML += "<body>Enter some text:";
this.Controls.Add( new LiteralControl( strOpenHTML ) );
// Add HTMLForm Tag
HtmlForm frmForm = new HtmlForm();
frmForm.ID = "myForm";
Controls.Add( frmForm );
// Add a TextBox
txtTextBox.ID = "myTextBox";
frmForm.Controls.Add( txtTextBox );
// Add a Button
Button btnButton = new Button();
btnButton.Text = "Click Here!";
//AddHandler btnButton.Click, AddressOf Button_Click;
btnButton.Click += new EventHandler(Button_Click);
frmForm.Controls.Add( btnButton );
btnButton.Text = "Click Here!";
frmForm.Controls.Add( btnButton );
// Add Page Break
frmForm.Controls.Add( new LiteralControl( "<p>" ) );
// Add a Label
lblLabel.ID = "myLabel";
frmForm.Controls.Add( lblLabel );
// Add Closing HTML Tags
string strCloseHTML;
strCloseHTML = "</form></body></html>";
Controls.Add( new LiteralControl( strCloseHTML ) );
}
void Button_Click( object s, EventArgs e )
{
lblLabel.Text = txtTextBox.Text;
}
}
I can get my cs to compile but on return my page is blank. I think there might be something wrong with my .cs file--but can not see anything right off. Can any of you see where I might be off a little. (ok-well with my code)
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace myPage
{
public class myPage:Control
{
protected System.Web.UI.WebControls.TextBox txtTextBox;
protected System.Web.UI.WebControls.Label lblLabel;
public void CreateChildControls(HtmlTextWriter stringWriter)
{
// Use htmlWriter to write HTML.
string strOpenHTML;
strOpenHTML = "<html><head><title>My Page</title></head>";
strOpenHTML += "<body>Enter some text:";
this.Controls.Add( new LiteralControl( strOpenHTML ) );
// Add HTMLForm Tag
HtmlForm frmForm = new HtmlForm();
frmForm.ID = "myForm";
Controls.Add( frmForm );
// Add a TextBox
txtTextBox.ID = "myTextBox";
frmForm.Controls.Add( txtTextBox );
// Add a Button
Button btnButton = new Button();
btnButton.Text = "Click Here!";
//AddHandler btnButton.Click, AddressOf Button_Click;
btnButton.Click += new EventHandler(Button_Click);
frmForm.Controls.Add( btnButton );
btnButton.Text = "Click Here!";
frmForm.Controls.Add( btnButton );
// Add Page Break
frmForm.Controls.Add( new LiteralControl( "<p>" ) );
// Add a Label
lblLabel.ID = "myLabel";
frmForm.Controls.Add( lblLabel );
// Add Closing HTML Tags
string strCloseHTML;
strCloseHTML = "</form></body></html>";
Controls.Add( new LiteralControl( strCloseHTML ) );
}
void Button_Click( object s, EventArgs e )
{
lblLabel.Text = txtTextBox.Text;
}
}