Hello,
I have created few dynamic text controls and I have a button which becomes visible when these controls are created. After I enter some text and press button, my text in dynamic text boxes is diappearing.
Please advice
Thanks
Lots of potential issues. Make sure that every code-path that needs the dynamic controls, creates the dynamic controls. Make sure that you're creating the dynamic controls at the appropriate point in the ASP.NET Page Life-cycle. More information about dynamic controls and the page cycle:
Thanks tgreer. Here is my code. I think I tried everything.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
if (IsPostBack)
{
if (ViewState["mode"].ToString() == "1")
{
CreateComputerControls();
}
}
else
{
ViewState.Add("mode","0");
}
}
catch(Exception X)
{
//Redirect to different page
Thanks for your quick reply.As in my code above, when I select some thing from dropdownlist, it hits pageload but returns error object referance not set to an instance of variable.
I think may be its due to my setting viewstate mode to 1 doesnt occur untill I load controls. But how do I check post back?
Thanks again
The Page_Init is the best solution if your process is not dependent on user input. You can't read or write values to your other controls until page_load. So you can't ask if checkbox is checked then add control dynamic control.
If you have unlimited number of controls you may be adding then this could get complicated.
If the max number may be 10 then add 10 controls and set there visible to False then turn them on as needed.
fmt... that article I linked to directly addresses issues with ViewState, PostBack, and dynamic controls. If there is an error or something missing, let me know. I think, though, that your question has been fully answered!
Yes,Thanks.Its very good article .I have it as referance for my current project. I am new to asp.net and I am going through pitfalls. I resolved the issue of viewstate but I am still having problems retrieving values from dynamic text boxes. Any suggestions will be greatly appreciated as ever.
THANKS
If the control is created PRIOR TO the LoadPostBackData stage, then there should be no problems retrieving the data from the controls during the Load stage.
As a test, try iterating through Request.Form to make sure the data is really even being collected and submitted.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.