Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access dynamic controls in codebehind

Status
Not open for further replies.

kurie

Programmer
Jun 4, 2008
170
ZA
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} }

}
}
 
Hi

Sorry, but personally I have no idea about what is a "code behind" and what [tt]runat="server"[/tt] does. If you can describe exactly what you want to happen there, is more possible that one of us will help you. Otherwise you will have to wait for someone who knows those things.

Maybe I am wrong, but my theory is that could be similar to Jaxer. There are also used [tt]runat="server"[/tt] attributes to automate Ajax calls. This would make me visit forum1600.

Feherke.
 
sorry, my bad,
by code behind i meant vb.net or c#. i need to access the control values from vb.net or c#.
runat = "server" makes an html control appear server side, meaning you can access a div control from vb.net code.

Thanks
 
Whatever the setup, to access client-side data server-side, you will need to somehow send that data to the server.

Whether it's via an AJAX call, whether it's via a form GET/POST, or some other URL GET request (e.g. IMG src, etc) it doesn't matter... but you will need to send it somehow.

If you have an idea of how you want to do it, then let us know - otherwise I'd investigate all of the methods I've just mentioned to see which suits you best.

If you are already sending the data, but cannot receive it, then you'd need to ask in the relevant .Net forum about how best to do this, as it would no longer be a client-side problem.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thanks very much
I im not sending the server side, i didnt know i have to do that for controls like textbox, i was thinking even if they are created by javascript they are sent to the server side by default.
i guess i have to sent each control as soon as i create it.

im not sure which method im suppose to use, you help on this is highly appreciated maybe with links to tutorials as well. Mean while i will also do some reaserch on this.

Thanks very much
 
Perhaps you should ask for more help in the .Net forums anyway - if this is something that is done often, then they may be able to provide a cleaner way of doing it that integrates with .Net controls.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top