|
-
Dec 5th, 2005, 10:19 AM
#1
Thread Starter
Member
custom control - please help
Hello Guys,
I am trying to write a custom control for my project. Basically what I am doing is converting a asp project to asp .net.
I have built a system to create a survey. Basically it allows the user to type in the text and it converts appropriate
html questions as they select the question type radio, dropdown, text box etc. In the end the system builds up the survey which is a html form and stores it in the database.
Then I am calling a function to display the survey online. Once the survey is being filled by public users.
it is sent to database. It works fine in asp.
now I need to convert the stuff to .net.
As for as I know, I have to make all the html element to runat = "server" and those controls needs to be declared as
protected System.Web.UI.HtmlControls etc......
The thing is if I know what are the html controls are been used, I will be able to do that in .net without any problems.
but here I dont know what are the controls going to be created...
So I have thought of using custom controls
here are the codes I have used,
using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Web.UI.WebControls;
namespace SurveyCustomControl
{
/// <summary>
/// Summary description for QuestionsControl.
/// </summary>
[DefaultProperty("ContentContext"),
ToolboxData("<{0}:QuestionsControl runat=server></{0}QuestionsControl>")]
public class QuestionsControl : Control, INamingContainer
{
public QuestionsControl(string controlName, string controlValue)
{
this.controlName = controlName;
this.controlValue = controlValue;
}
protected override void CreateChildControls()
{
if(ControlName.ToLower() == "checkbox")
{
HtmlInputCheckBox ControlValue = new HtmlInputCheckBox();
Controls.Add(ControlValue);
}
else if(ControlName.ToLower() == "radioacross")
{
HtmlInputRadioButton ControlValue = new HtmlInputRadioButton();
Controls.Add(ControlValue);
}
else if(ControlName.ToLower() == "textbox")
{
HtmlInputText ControlValue = new HtmlInputText();
Controls.Add(ControlValue);
}
else if(ControlName.ToLower() == "radio")
{
HtmlInputRadioButton ControlValue = new HtmlInputRadioButton();
Controls.Add(ControlValue);
}
else if(ControlName.ToLower() == "dropdown")
{
HtmlSelect ControlValue = new HtmlSelect();
Controls.Add(ControlValue);
}
else if(ControlName.ToLower() == "rating")
{
HtmlInputRadioButton ControlValue = new HtmlInputRadioButton();
Controls.Add(ControlValue);
}
else if(ControlName.ToLower() == "multiplerating")
{
HtmlInputRadioButton ControlValue = new HtmlInputRadioButton();
Controls.Add(ControlValue);
}
else if(ControlName.ToLower() == "textarea")
{
HtmlInputRadioButton ControlValue = new HtmlInputRadioButton();
Controls.Add(ControlValue);
}
HtmlButton btn = new HtmlButton();
btn.ID ="Go";
Controls.Add(btn);
}
#region Properties
[Category("Behavior"),
Description("ControlName")]
public string ControlName
{
get
{
return controlName;
}
set
{
controlName = value;
}
}
[Category("Behavior"),
Description("ControlValue")]
public string ControlValue
{
get
{
return controlValue;
}
set
{
controlValue = value;
}
}
#endregion
#region Fields
public string controlName;
public string controlValue;
#endregion
}
}
but it is not really working, Can you guys tell me what to do....or some advice as I am bit stuck with it and i dont have anyone near to ask about it.
Cheers,
dummy_pmgr
Last edited by dummy_pmgr; Dec 6th, 2005 at 04:21 AM.
***learning everyday ***
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|