View Full Version : Need some help with user controls...

01-17-2007, 12:17 AM
I'm trying to write a little survey program that will run a user through a series of survey questions. Each user could potentially have different questions asked of them, so i've created a bunch of user controls (.ascx) files, each pertaining to a "survey page". I'm having problems getting it to work correctly, so i was hoping someone could lend some advice on how to set it up...

I basically have one page that is "controlling" which page shows up and running them through each page. Below is basically how this page is working... The main problem is that these user controls have to be loaded in page_init to be available within the viewstate, but i don't know at init what control will be loaded next... Please let me know how I can set it up to work like I'd like it to...

<%@ Page Language="C#" MasterPageFile="~/survey.master" Title="Surveys" %>
<%@ Import Namespace="SurveyWebControls" %>
<script runat="server">
const string SurveyStart = "SurveyStart";

ISurveyPageBase currentSurveyPage;

protected void Page_PreInit(object sender, EventArgs e)
Page.Theme = "SurveyDefault";

protected void Page_Load(object sender, EventArgs e)
lblErrorMessage.Text = "";

if (!Page.IsPostBack)

protected void btnNext_Click(object sender, ImageClickEventArgs e)
if (currentSurveyPage.Validated)
lblErrorMessage.Text = currentSurveyPage.ErrorMessage + "<br />";

private void LoadSurveyPage(string QId)
currentSurveyPage = (SurveyPageBase)LoadControl(QId + ".ascx");
txtCurrentSurveyPage.Value = currentSurveyPage.PageId;
btnNext.Visible = currentSurveyPage.ShowNext;

<asp:Content ID="SurveyBody" ContentPlaceHolderID="SurveyBody" Runat="Server">
<asp:UpdatePanel ID="SurveyUpdatePanel" runat="server">
<asp:HiddenField runat="server" ID="txtCurrentSurveyPage" />
<asp:Label runat="server" ID="lblErrorMessage" SkinID="ErrorMessage" />
<asp:PlaceHolder ID="Survey" runat="server" />
<br /><br />
<asp:ImageButton ID="btnNext" SkinID="NextButton" runat="server" OnClick="btnNext_Click" />