i have json stored in hidden field of aspx page.
[{"Field_Control_Id":"txtName","Field_Control_Type":"TextBox","Field_Height":40,"Field_Name":"Name","Field_Width":60,"Field_XPos":100,"Field_YPos":200},{"Field_Control_Id":"txtAddress","Field_Control_Type":"TextBox","Field_Height":20,"Field_Name":"Address","Field_Width":300,"Field_XPos":200,"Field_YPos":300},{"Field_Control_Id":"txtDateOfBirth","Field_Control_Type":"DropDownList","Field_Height":50,"Field_Name":"DOB","Field_Width":250,"Field_XPos":350,"Field_YPos":450}]
what i want is a html page should be created based on data in json i.e., if its textBox with controlid txtname then a textbox(input type ... ) should be created in html with id txtname and same for all other data present and then that html should be rendered into panel in aspx page.
how can i do this. what should be approach?
KalaiPosted Feb 17, 2014, 7:14 AM
json.aspx
==========
json.aspx.cs
============
using Newtonsoft.Json.Linq;
protected void Page_Load(object sender, EventArgs e)
{
string HiddenField = HF.Value;
if(!string.IsNullOrEmpty(HiddenField))
{
string[] arr = new string[10];
arr = HiddenField.Split(new string[] { "}," }, StringSplitOptions.None);
TextBox[] textBoxes = new TextBox[10];
Label[] labels = new Label[10];
DropDownList[] DropDownList = new DropDownList[10];
if (arr.Count() > 0)
{
for (int i = 0; i < arr.Count(); i++)
{
string val = string.Empty;
if (i == arr.Count() - 1)
{
val = arr[i].ToString();
}
else
{
val = arr[i].ToString() + "}";
}
dynamic stuff = JObject.Parse(val);
string id = stuff.Field_Control_Id;
string type = stuff.Field_Control_Type;
string name = stuff.Field_Name;
labels[i] = new Label();
labels[i].Text = name;
labels[i].Attributes.Add("runat", "server");
p1.Controls.Add(labels[i]);
if (type == "TextBox")
{
textBoxes[i] = new TextBox();
textBoxes[i].ID = id;
textBoxes[i].Attributes.Add("runat", "server");
p1.Controls.Add(textBoxes[i]);
}
if (type == "DropDownList")
{
DropDownList[i] = new DropDownList();
DropDownList[i].ID = id;
DropDownList[i].Attributes.Add("runat", "server");
p1.Controls.Add(DropDownList[i]);
}
}
}
}
}