im creating controls using javascript, and i would like to retrieve the values of the controls in code behind(vb.net/c#) . My vb.net below is not returning them,
Odata is a div but i added the runat = "server" property. Would anyone know what im doing wrong.
Dim ctr As System.Web.UI.Control ' Web.System.Web.UI.Control
For Each ctr In oData.Controls
Windows.Forms.MessageBox.Show(ctr.ID)
Next ctr
and the javascript code below.
function LoadControls(strParams)
{
//var arr = [];
//arr = strParams.split(",");
//var strParams = '<%=strParams%>';
// alert(strParams);
var MyHeight;
MyHeight = 0;
var di =document.getElementById('oData');
var SimpleString = strParams;
var myArray = [];
myArray = SimpleString.split(",");
for (var i = 0; i < myArray.length; i++)
{
var str = myArray;
var j = new Array(2);
j = str.split("-");
if (j[1] == "Integer")
{
var txt5 = document.createElement("input");
txt5.setAttribute ('type', 'text');
txt5.setAttribute ('id', j[0]);
txt5.setAttribute ('name', j[0]);
txt5.setAttribute ('text', j[0]);
var chk1 = document.createElement("input");
chk1.setAttribute ('type', 'checkbox');
chk1.setAttribute ('id', "chk" + j[0] );
chk1.setAttribute ('name',"chk" + j[0]);
chk1.setAttribute ('text',"chk" + j[0]);
//chk1.innerHTML = "Default";
var lbl1 = document.createElement('label');
lbl1.setAttribute ('id', "lblDefault" );
lbl1.innerHTML = "Default";
lbl1.style.width = "30px";
var lbl2 = document.createElement('label');
lbl2.setAttribute ('id', "lblNull");
lbl2.innerHTML = "Nulls";
lbl2.style.width = "30px";
var lbl3 = document.createElement('label');
lbl3.setAttribute ('id', "lbl" + j[0]);
lbl3.innerHTML = j[0];
lbl3.style.width = "125px";
var chk2 = document.createElement("input");
chk2.setAttribute ('type', 'checkbox');
chk2.setAttribute ('id', "chkNull" );
chk2.setAttribute ('name',"chkNull");
chk2.setAttribute ('text',"Null");
//chk2.innerHTML = "null";
//txt5.value = j[0];
txt5.style.top='15px';
txt5.style.left='15px';
var newdiv = document.createElement('div');
newdiv.setAttribute('id',"divIdName");
newdiv.appendChild(lbl3);
newdiv.appendChild(txt5);
newdiv.appendChild(chk2);
newdiv.appendChild(lbl2);
newdiv.appendChild(chk1);
newdiv.appendChild(lbl1);
di.appendChild(newdiv);
}
else if (j[1] == "Boolean")
{
var txt1 = document.createElement("input");
txt1.setAttribute ('type', 'radio');
txt1.setAttribute ('id', j[0]);
txt1.setAttribute ('name',j[0]);
txt1.setAttribute ('text',j[0]);
txt1.value = j[0];
//txt1.innerText = j[0];
txt1.style.top= MyHeight + 'px'; // '15px';
txt1.style.left='0px';
//rbtnfalse
var rbtn1 = document.createElement("input");
rbtn1.setAttribute ('type', 'radio');
rbtn1.setAttribute ('id',"rbtnF" + j[0]);
rbtn1.setAttribute ('name',"rbtnF" + j[0]);
rbtn1.setAttribute ('text',"rbtnF" + j[0]);
rbtn1.value = j[0];
//chkNull
var chkNull = document.createElement("input");
chkNull.setAttribute ('type', 'checkbox');
chkNull.setAttribute ('id',"chkNull" + j[0]);
chkNull.setAttribute ('name',"chkNull" + j[0]);
chkNull.setAttribute ('text',"chkNull" + j[0]);
//chkDefault
var chkDefault = document.createElement("input");
chkDefault.setAttribute ('type', 'checkbox');
chkDefault.setAttribute ('id',"chkD" + j[0]);
chkDefault.setAttribute ('name',"chkD" + j[0]);
chkDefault.setAttribute ('text',"chkD" + j[0]);
var lbl = document.createElement('label');
lbl.setAttribute ('id', "lbl" + j[0]);
lbl.innerHTML = j[0];
lbl.style.width = "120px";
lbl.style.weight = "bold";
var lbl1 = document.createElement('label');
lbl1.setAttribute ('id', "lblTrue" + j[0]);
lbl1.innerHTML = "True";
lbl1.style.width = "50px";
lbl1.style.weight = "bold";
var lbl2 = document.createElement('label');
lbl2.setAttribute ('id', "lblFalse" + j[0]);
lbl2.innerHTML = "False";
lbl2.style.width = "50px";
lbl2.style.weight = "bold";
var lbl4 = document.createElement('label');
lbl4.setAttribute ('id', "lblD" + j[0]);
lbl4.innerHTML = "Default";
lbl4.style.width = "50px";
lbl4.style.weight = "bold";
var lbl5 = document.createElement('label');
lbl5.setAttribute ('id', "lblN" + j[0]);
lbl5.innerHTML = "Null";
lbl5.style.width = "50px";
lbl5.style.weight = "bold";
//txt1.style.width='10px';
//txt1.style.height='20px';
//txt5.style.visibility = 'visible'; // default anyway
var newdiv = document.createElement('div');
newdiv.setAttribute('id',"divIdName");
newdiv.appendChild(lbl);
newdiv.appendChild(txt1);
newdiv.appendChild(lbl1);
newdiv.appendChild(rbtn1);
newdiv.appendChild(lbl2);
newdiv.appendChild(chkNull);
newdiv.appendChild(lbl5);
newdiv.appendChild(chkDefault);
newdiv.appendChild(lbl4);
di.appendChild(newdiv);
txt1.onclick=function() { if (this.checked==true) { this.checked = false} else {this.checked =true} }
}
}
Odata is a div but i added the runat = "server" property. Would anyone know what im doing wrong.
Dim ctr As System.Web.UI.Control ' Web.System.Web.UI.Control
For Each ctr In oData.Controls
Windows.Forms.MessageBox.Show(ctr.ID)
Next ctr
and the javascript code below.
function LoadControls(strParams)
{
//var arr = [];
//arr = strParams.split(",");
//var strParams = '<%=strParams%>';
// alert(strParams);
var MyHeight;
MyHeight = 0;
var di =document.getElementById('oData');
var SimpleString = strParams;
var myArray = [];
myArray = SimpleString.split(",");
for (var i = 0; i < myArray.length; i++)
{
var str = myArray;
var j = new Array(2);
j = str.split("-");
if (j[1] == "Integer")
{
var txt5 = document.createElement("input");
txt5.setAttribute ('type', 'text');
txt5.setAttribute ('id', j[0]);
txt5.setAttribute ('name', j[0]);
txt5.setAttribute ('text', j[0]);
var chk1 = document.createElement("input");
chk1.setAttribute ('type', 'checkbox');
chk1.setAttribute ('id', "chk" + j[0] );
chk1.setAttribute ('name',"chk" + j[0]);
chk1.setAttribute ('text',"chk" + j[0]);
//chk1.innerHTML = "Default";
var lbl1 = document.createElement('label');
lbl1.setAttribute ('id', "lblDefault" );
lbl1.innerHTML = "Default";
lbl1.style.width = "30px";
var lbl2 = document.createElement('label');
lbl2.setAttribute ('id', "lblNull");
lbl2.innerHTML = "Nulls";
lbl2.style.width = "30px";
var lbl3 = document.createElement('label');
lbl3.setAttribute ('id', "lbl" + j[0]);
lbl3.innerHTML = j[0];
lbl3.style.width = "125px";
var chk2 = document.createElement("input");
chk2.setAttribute ('type', 'checkbox');
chk2.setAttribute ('id', "chkNull" );
chk2.setAttribute ('name',"chkNull");
chk2.setAttribute ('text',"Null");
//chk2.innerHTML = "null";
//txt5.value = j[0];
txt5.style.top='15px';
txt5.style.left='15px';
var newdiv = document.createElement('div');
newdiv.setAttribute('id',"divIdName");
newdiv.appendChild(lbl3);
newdiv.appendChild(txt5);
newdiv.appendChild(chk2);
newdiv.appendChild(lbl2);
newdiv.appendChild(chk1);
newdiv.appendChild(lbl1);
di.appendChild(newdiv);
}
else if (j[1] == "Boolean")
{
var txt1 = document.createElement("input");
txt1.setAttribute ('type', 'radio');
txt1.setAttribute ('id', j[0]);
txt1.setAttribute ('name',j[0]);
txt1.setAttribute ('text',j[0]);
txt1.value = j[0];
//txt1.innerText = j[0];
txt1.style.top= MyHeight + 'px'; // '15px';
txt1.style.left='0px';
//rbtnfalse
var rbtn1 = document.createElement("input");
rbtn1.setAttribute ('type', 'radio');
rbtn1.setAttribute ('id',"rbtnF" + j[0]);
rbtn1.setAttribute ('name',"rbtnF" + j[0]);
rbtn1.setAttribute ('text',"rbtnF" + j[0]);
rbtn1.value = j[0];
//chkNull
var chkNull = document.createElement("input");
chkNull.setAttribute ('type', 'checkbox');
chkNull.setAttribute ('id',"chkNull" + j[0]);
chkNull.setAttribute ('name',"chkNull" + j[0]);
chkNull.setAttribute ('text',"chkNull" + j[0]);
//chkDefault
var chkDefault = document.createElement("input");
chkDefault.setAttribute ('type', 'checkbox');
chkDefault.setAttribute ('id',"chkD" + j[0]);
chkDefault.setAttribute ('name',"chkD" + j[0]);
chkDefault.setAttribute ('text',"chkD" + j[0]);
var lbl = document.createElement('label');
lbl.setAttribute ('id', "lbl" + j[0]);
lbl.innerHTML = j[0];
lbl.style.width = "120px";
lbl.style.weight = "bold";
var lbl1 = document.createElement('label');
lbl1.setAttribute ('id', "lblTrue" + j[0]);
lbl1.innerHTML = "True";
lbl1.style.width = "50px";
lbl1.style.weight = "bold";
var lbl2 = document.createElement('label');
lbl2.setAttribute ('id', "lblFalse" + j[0]);
lbl2.innerHTML = "False";
lbl2.style.width = "50px";
lbl2.style.weight = "bold";
var lbl4 = document.createElement('label');
lbl4.setAttribute ('id', "lblD" + j[0]);
lbl4.innerHTML = "Default";
lbl4.style.width = "50px";
lbl4.style.weight = "bold";
var lbl5 = document.createElement('label');
lbl5.setAttribute ('id', "lblN" + j[0]);
lbl5.innerHTML = "Null";
lbl5.style.width = "50px";
lbl5.style.weight = "bold";
//txt1.style.width='10px';
//txt1.style.height='20px';
//txt5.style.visibility = 'visible'; // default anyway
var newdiv = document.createElement('div');
newdiv.setAttribute('id',"divIdName");
newdiv.appendChild(lbl);
newdiv.appendChild(txt1);
newdiv.appendChild(lbl1);
newdiv.appendChild(rbtn1);
newdiv.appendChild(lbl2);
newdiv.appendChild(chkNull);
newdiv.appendChild(lbl5);
newdiv.appendChild(chkDefault);
newdiv.appendChild(lbl4);
di.appendChild(newdiv);
txt1.onclick=function() { if (this.checked==true) { this.checked = false} else {this.checked =true} }
}
}