Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I would like someone to help me plese.
I'm wrting a web custom cotrol that displays a questionnaire.
I have the next button, registered to click event, and the client has a Navigate event
On navigate i want to change the questionnaire, the object is changed but the page stays with the previous questionnaire.
(on the second click on next button the questionnaire is changed)

Here is my control code
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebQuestionnaireControl runat="server">")]
public class WebQuestionnaireControl:WebControl, INamingContainer
{
public delegate void LoagControlHandler(object sender, WebQuestionnaireControlEventArgs e);
public delegate void NavigationHandler (object sender, WebQuestionnaireControlEventArgs e);
private HtmlTable _pageTable;
private HtmlTableRow _pageRow;
private HtmlTableCell _pageCell;
private HtmlTable _tQtnrName;
private HtmlTableRow _rQtnrName;
private HtmlTableCell _cQtnrName;
private Label qtnrName;
private HtmlTable _tNavigate;
private HtmlTableRow _rNavigate;
private HtmlTableCell _cNavigate;
private HtmlTable _tButtons;
private HtmlTableRow _rButtons;
private HtmlTableCell _cNext;
private HtmlTableCell _cPrev;
private HtmlTableCell _cSave;
private HtmlTableCell _cSubmit;
private Button btnNext;

public event NavigationHandler Navigate;
public event LoagControlHandler Load;

#region Properties
[Browsable(true),
Bindable(true),
Category("Objects"),
Description("The websurveys questionnaire")]
public Questionnaire Qtnr
{
get
{

return (Questionnaire)ViewState["Qtnr"];
}
set
{
ViewState["Qtnr"] = value;
}
}
#endregion

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!Page.IsPostBack && this.Load != null)
{
var args = new WebQuestionnaireControlEventArgs();
this.Load.Invoke(this, args);
if (args.CanProceed)
{
Qtnr = args.Qtnr;
}
}
}

protected override void CreateChildControls()
{
base.CreateChildControls();

_pageTable = new HtmlTable();
_pageTable.Attributes.Add("class", "PageTable");
_pageRow = new HtmlTableRow();
_pageCell = new HtmlTableCell();
_pageTable.Rows.Add(_pageRow);
_pageRow.Cells.Add(_pageCell);

_tQtnrName = new HtmlTable();
_tQtnrName.Attributes.Add("class", "PageTable");
_rQtnrName = new HtmlTableRow();
_cQtnrName = new HtmlTableCell {Align = "center"};
_tQtnrName.Rows.Add(_rQtnrName);
_rQtnrName.Cells.Add(_cQtnrName);

qtnrName = new Label
{
CssClass = "QtnrName",
Text = Qtnr != null && Qtnr.ShowCaption ? Qtnr.Name : ""
};

_pageCell.Controls.Add(_tQtnrName);
_cQtnrName.Controls.Add(qtnrName);

this.Controls.Add(_pageTable);

_tNavigate = new HtmlTable();
_tNavigate.Attributes.Add("class", "Navigate");
_rNavigate = new HtmlTableRow();
_cNavigate = new HtmlTableCell();
_tNavigate.Rows.Add(_rNavigate);
_rNavigate.Cells.Add(_cNavigate);

_tButtons = new HtmlTable();
_rButtons = new HtmlTableRow();
_cPrev = new HtmlTableCell();
_cNext = new HtmlTableCell();
_cSave = new HtmlTableCell();
_cSubmit = new HtmlTableCell();
_tButtons.Rows.Add(_rButtons);
_rButtons.Cells.Add(_cPrev);
_rButtons.Cells.Add(_cNext);
_rButtons.Cells.Add(_cSave);
_rButtons.Cells.Add(_cSubmit);
_cNavigate.Controls.Add(_tButtons);

btnNext = new Button {Text = "Next>"};
btnNext.Click += new System.EventHandler(btnNext_Click);
_cNext.Controls.Add(btnNext);

this.Controls.Add(_tNavigate);
}

protected virtual void btnNext_Click(object sender, System.EventArgs e)
{
if(Navigate!=null)
{
var args = new WebQuestionnaireControlEventArgs() {NavigateType = NavigateTypeEnum.Next};
Navigate.Invoke(this, args);
if(args.CanProceed)
{
Qtnr = args.Qtnr;
CreateChildControls();//Here i need the controls will be created with the new questionnaire
}
}
}

protected override void OnPreRender(System.EventArgs e)
{
base.OnPreRender(e);
string cssResource = "WebQuestionnaireControl.Styles.WebQtnrControlStyle.css";
string cssResourceURL = Page.ClientScript.GetWebResourceUrl(this.GetType(), cssResource);
var cssLink = new HtmlLink { Href = cssResourceURL };
cssLink.Attributes.Add("rel", "stylesheet");
this.Page.Header.Controls.Add(cssLink);
}

}

here is my page code
C#
protected void text_Navigate(object sender, Ransys.Web.UI.Controls.WebQuestionnaireControlEventArgs e)
      {
          var fcd = new Facade();
          e.CanProceed = true;
          e.Qtnr = fcd.GetQuestionnaireByID(32);
      }

      protected void text_Load(object sender, Ransys.Web.UI.Controls.WebQuestionnaireControlEventArgs e)
      {
          var fcd = new Facade();
          e.CanProceed = true;
          e.Qtnr = fcd.GetQuestionnaireByID(29);
      }



Thank you very much :)
Posted
Updated 11-Apr-12 0:21am
v4

1 solution

Hi I got it, I added this.Controls.Clear(); in CreateChildControls();
and it works fine.

Is it correct to work like this?

Thank you again :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900