K
Kevin Phifer
Ok, before anyone freaks out, I have a solution I need to
create that gathers content from maybe different places.
Each one can return a <form> in the html, so its the
classic can't have more than one runat=server form on a
asp.net page. However, I still want developers to be able
to use asp.net controls to create some apps that are
created on the page. So I need multiple forms on a
asp.net page(doesn't everyone). I purchased the Wilson
Webform deal that got me started, but not quite all the
way there. My basic problems is when I tell the seperate
page to render it does, but the viewstate calls return
nothing....here comes some code:
the Page Class I created as follows, some comments inline
public class MyPage:System.Web.UI.Page
{
StringBuilder _myStringBuilder;
public MyPage():base()
{
_myStringBuilder = new
StringBuilder();
}
public StringBuilder myStringBuilder
{
get{return _myStringBuilder;}
}
protected override object
LoadPageStateFromPersistenceMedium()
{
return Session["ViewState" +
this.ID];
}
protected override void
SavePageStateToPersistenceMedium(object viewState)
{
//here is where my problem begins, when called
//viewstate == null
Session["ViewState" + this.ID] =
viewState;
}
protected override void Render
(System.Web.UI.HtmlTextWriter writer)
{
//I "steal" the html because if i don't it
//shows up on my main page
_myStringBuilder = new
StringBuilder();
System.IO.StringWriter sw = new
System.IO.StringWriter(_myStringBuilder);
System.Web.UI.HtmlTextWriter htw =
new System.Web.UI.HtmlTextWriter(sw);
base.Render (htw);
}
protected override void OnInit(EventArgs e)
{
//wilson form says I have to do this not sure
base.OnInit (e);
this.RegisterViewStateHandler();
}
-=-=-=-=-
Ok that being the Page class I create my page and execute
it with the following:
in the code behind page.....
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the
page here
MyPage myPage = new MyPage();
myPage.ID = "word";
myPage.EnableViewState=true;
myPage.Load+=new EventHandler
(myPage_Load);
System.Web.UI.HtmlControls.HtmlForm myForm = new
System.Web.UI.HtmlControls.HtmlForm();
myForm.ID = "myForm";
myPage.Controls.Add(myForm);
((IHttpHandler)
myPage).ProcessRequest(Context);
Literal1.Text =
myPage.myStringBuilder.ToString();
}
private void myPage_Load(object sender,
EventArgs e)
{
TextBox t1 = new TextBox();
t1.AutoPostBack=true;
t1.ID = "myTextBox";
((System.Web.UI.HtmlControls.HtmlForm)
((System.Web.UI.Page)sender).FindControl
("myForm")).Controls.Add(t1);
}
}
This all works great, textbox gets the postback info and
everything, the only thing is that viewstate object
in "protected override void
SavePageStateToPersistenceMedium(object viewState)" comes
back as null.
Anyone have any idea, I assume I'm not calling the Page
object correctly, or somehow need to instantiate the
viewstate or something. I've been fighting this for a
week now. Any suggestions would be greatly appreciated....
Thanx in advance...
create that gathers content from maybe different places.
Each one can return a <form> in the html, so its the
classic can't have more than one runat=server form on a
asp.net page. However, I still want developers to be able
to use asp.net controls to create some apps that are
created on the page. So I need multiple forms on a
asp.net page(doesn't everyone). I purchased the Wilson
Webform deal that got me started, but not quite all the
way there. My basic problems is when I tell the seperate
page to render it does, but the viewstate calls return
nothing....here comes some code:
the Page Class I created as follows, some comments inline
public class MyPage:System.Web.UI.Page
{
StringBuilder _myStringBuilder;
public MyPage():base()
{
_myStringBuilder = new
StringBuilder();
}
public StringBuilder myStringBuilder
{
get{return _myStringBuilder;}
}
protected override object
LoadPageStateFromPersistenceMedium()
{
return Session["ViewState" +
this.ID];
}
protected override void
SavePageStateToPersistenceMedium(object viewState)
{
//here is where my problem begins, when called
//viewstate == null
Session["ViewState" + this.ID] =
viewState;
}
protected override void Render
(System.Web.UI.HtmlTextWriter writer)
{
//I "steal" the html because if i don't it
//shows up on my main page
_myStringBuilder = new
StringBuilder();
System.IO.StringWriter sw = new
System.IO.StringWriter(_myStringBuilder);
System.Web.UI.HtmlTextWriter htw =
new System.Web.UI.HtmlTextWriter(sw);
base.Render (htw);
}
protected override void OnInit(EventArgs e)
{
//wilson form says I have to do this not sure
base.OnInit (e);
this.RegisterViewStateHandler();
}
-=-=-=-=-
Ok that being the Page class I create my page and execute
it with the following:
in the code behind page.....
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the
page here
MyPage myPage = new MyPage();
myPage.ID = "word";
myPage.EnableViewState=true;
myPage.Load+=new EventHandler
(myPage_Load);
System.Web.UI.HtmlControls.HtmlForm myForm = new
System.Web.UI.HtmlControls.HtmlForm();
myForm.ID = "myForm";
myPage.Controls.Add(myForm);
((IHttpHandler)
myPage).ProcessRequest(Context);
Literal1.Text =
myPage.myStringBuilder.ToString();
}
private void myPage_Load(object sender,
EventArgs e)
{
TextBox t1 = new TextBox();
t1.AutoPostBack=true;
t1.ID = "myTextBox";
((System.Web.UI.HtmlControls.HtmlForm)
((System.Web.UI.Page)sender).FindControl
("myForm")).Controls.Add(t1);
}
}
This all works great, textbox gets the postback info and
everything, the only thing is that viewstate object
in "protected override void
SavePageStateToPersistenceMedium(object viewState)" comes
back as null.
Anyone have any idea, I assume I'm not calling the Page
object correctly, or somehow need to instantiate the
viewstate or something. I've been fighting this for a
week now. Any suggestions would be greatly appreciated....
Thanx in advance...