473,395 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

access dynamic controls in codebehind

10
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.
Expand|Select|Wrap|Line Numbers
  1. Dim ctr As System.Web.UI.Control '  Web.System.Web.UI.Control
  2.         For Each ctr In oData.Controls
  3.             Windows.Forms.MessageBox.Show(ctr.ID)
  4.         Next ctr
and the javascript code below.


Expand|Select|Wrap|Line Numbers
  1. function LoadControls(strParams)
  2. {       
  3.         //var arr = [];
  4.         //arr = strParams.split(",");
  5.       //var strParams = '<%=strParams%>';
  6.      // alert(strParams);
  7.       var MyHeight;
  8.       MyHeight = 0;
  9.       var di =document.getElementById('oData');
  10.       var SimpleString = strParams; 
  11.       var myArray = [];
  12.       myArray = SimpleString.split(",");
  13.       for (var i = 0; i < myArray.length; i++) 
  14.       {
  15.             var str = myArray[i];
  16.             var j = new Array(2);
  17.             j = str.split("-");
  18.  
  19.             if (j[1] == "Integer")
  20.             {
  21.               var txt5   = document.createElement("input");
  22.               txt5.setAttribute ('type', 'text');
  23.               txt5.setAttribute ('id', j[0]);
  24.               txt5.setAttribute ('name', j[0]);
  25.               txt5.setAttribute ('text', j[0]);
  26.               var chk1 = document.createElement("input");
  27.               chk1.setAttribute ('type', 'checkbox');
  28.               chk1.setAttribute ('id', "chk" + j[0] );
  29.               chk1.setAttribute ('name',"chk" +  j[0]);
  30.               chk1.setAttribute ('text',"chk" +  j[0]); 
  31.               //chk1.innerHTML  = "Default";
  32.               var lbl1   = document.createElement('label');
  33.               lbl1.setAttribute ('id', "lblDefault" );
  34.               lbl1.innerHTML =  "Default";
  35.               lbl1.style.width = "30px";
  36.               var lbl2   = document.createElement('label');
  37.               lbl2.setAttribute ('id', "lblNull");
  38.               lbl2.innerHTML =  "Nulls";
  39.               lbl2.style.width = "30px";
  40.               var lbl3   = document.createElement('label');
  41.               lbl3.setAttribute ('id', "lbl" + j[0]);
  42.               lbl3.innerHTML =  j[0];
  43.               lbl3.style.width = "125px";
  44.               var chk2   = document.createElement("input");
  45.               chk2.setAttribute ('type', 'checkbox');
  46.               chk2.setAttribute ('id', "chkNull" );
  47.               chk2.setAttribute ('name',"chkNull");
  48.               chk2.setAttribute ('text',"Null");
  49.               //chk2.innerHTML  = "null";
  50.               //txt5.value = j[0];
  51.               txt5.style.top='15px';
  52.               txt5.style.left='15px';
  53.               var newdiv = document.createElement('div');
  54.               newdiv.setAttribute('id',"divIdName");                            
  55.               newdiv.appendChild(lbl3);
  56.               newdiv.appendChild(txt5);
  57.               newdiv.appendChild(chk2);              
  58.               newdiv.appendChild(lbl2);
  59.               newdiv.appendChild(chk1);
  60.               newdiv.appendChild(lbl1);
  61.               di.appendChild(newdiv);
  62.              }
  63.             else if (j[1] == "Boolean")
  64.             {
  65.               var txt1   = document.createElement("input");
  66.               txt1.setAttribute ('type', 'radio');
  67.               txt1.setAttribute ('id', j[0]);
  68.               txt1.setAttribute ('name',j[0]);
  69.               txt1.setAttribute ('text',j[0]);
  70.               txt1.value = j[0];
  71.               //txt1.innerText = j[0];
  72.               txt1.style.top= MyHeight + 'px'; // '15px';
  73.               txt1.style.left='0px';
  74.               //rbtnfalse
  75.               var rbtn1   = document.createElement("input");
  76.               rbtn1.setAttribute ('type', 'radio');
  77.               rbtn1.setAttribute ('id',"rbtnF" +  j[0]);
  78.               rbtn1.setAttribute ('name',"rbtnF" + j[0]);
  79.               rbtn1.setAttribute ('text',"rbtnF" + j[0]);
  80.               rbtn1.value = j[0];
  81.                //chkNull
  82.               var chkNull   = document.createElement("input");
  83.               chkNull.setAttribute ('type', 'checkbox');
  84.               chkNull.setAttribute ('id',"chkNull" +  j[0]);
  85.               chkNull.setAttribute ('name',"chkNull" + j[0]);
  86.               chkNull.setAttribute ('text',"chkNull" + j[0]);
  87.              //chkDefault
  88.               var chkDefault   = document.createElement("input");
  89.               chkDefault.setAttribute ('type', 'checkbox');
  90.               chkDefault.setAttribute ('id',"chkD" +  j[0]);
  91.               chkDefault.setAttribute ('name',"chkD" + j[0]);
  92.               chkDefault.setAttribute ('text',"chkD" + j[0]);
  93.               var lbl   = document.createElement('label');
  94.               lbl.setAttribute ('id', "lbl" + j[0]);
  95.               lbl.innerHTML =  j[0];
  96.               lbl.style.width = "120px";
  97.               lbl.style.weight = "bold";
  98.               var lbl1   = document.createElement('label');
  99.               lbl1.setAttribute ('id', "lblTrue" + j[0]);
  100.               lbl1.innerHTML =  "True";
  101.               lbl1.style.width = "50px";
  102.               lbl1.style.weight = "bold";
  103.               var lbl2   = document.createElement('label');
  104.               lbl2.setAttribute ('id', "lblFalse" + j[0]);
  105.               lbl2.innerHTML =  "False";
  106.               lbl2.style.width = "50px";
  107.               lbl2.style.weight = "bold";
  108.               var lbl4   = document.createElement('label');
  109.               lbl4.setAttribute ('id', "lblD" + j[0]);
  110.               lbl4.innerHTML =  "Default";
  111.               lbl4.style.width = "50px";
  112.               lbl4.style.weight = "bold";
  113.               var lbl5   = document.createElement('label');
  114.               lbl5.setAttribute ('id', "lblN" + j[0]);
  115.               lbl5.innerHTML =  "Null";
  116.               lbl5.style.width = "50px";
  117.               lbl5.style.weight = "bold";
  118.               //txt1.style.width='10px';
  119.               //txt1.style.height='20px';
  120.               //txt5.style.visibility = 'visible'; // default anyway
  121.               var newdiv = document.createElement('div');
  122.               newdiv.setAttribute('id',"divIdName");              
  123.               newdiv.appendChild(lbl);
  124.               newdiv.appendChild(txt1);
  125.               newdiv.appendChild(lbl1);
  126.               newdiv.appendChild(rbtn1);                            
  127.               newdiv.appendChild(lbl2);  
  128.               newdiv.appendChild(chkNull);
  129.               newdiv.appendChild(lbl5);
  130.               newdiv.appendChild(chkDefault);
  131.               newdiv.appendChild(lbl4);            
  132.               di.appendChild(newdiv);
  133.               txt1.onclick=function() { if (this.checked==true) { this.checked = false} else {this.checked =true} }
  134.  
  135.             }
  136.       }
Mar 19 '09 #1
4 4741
omlac
10
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.
Expand|Select|Wrap|Line Numbers
  1. Dim ctr As System.Web.UI.Control '  Web.System.Web.UI.Control
  2.         For Each ctr In oData.Controls
  3.             Windows.Forms.MessageBox.Show(ctr.ID)
  4.         Next ctr
and the javascript code below.


Expand|Select|Wrap|Line Numbers
  1. function LoadControls(strParams)
  2. {       
  3.         //var arr = [];
  4.         //arr = strParams.split(",");
  5.       //var strParams = '<%=strParams%>';
  6.      // alert(strParams);
  7.       var MyHeight;
  8.       MyHeight = 0;
  9.       var di =document.getElementById('oData');
  10.       var SimpleString = strParams; 
  11.       var myArray = [];
  12.       myArray = SimpleString.split(",");
  13.       for (var i = 0; i < myArray.length; i++) 
  14.       {
  15.             var str = myArray[i];
  16.             var j = new Array(2);
  17.             j = str.split("-");
  18.  
  19.             if (j[1] == "Integer")
  20.             {
  21.               var txt5   = document.createElement("input");
  22.               txt5.setAttribute ('type', 'text');
  23.               txt5.setAttribute ('id', j[0]);
  24.               txt5.setAttribute ('name', j[0]);
  25.               txt5.setAttribute ('text', j[0]);
  26.               var chk1 = document.createElement("input");
  27.               chk1.setAttribute ('type', 'checkbox');
  28.               chk1.setAttribute ('id', "chk" + j[0] );
  29.               chk1.setAttribute ('name',"chk" +  j[0]);
  30.               chk1.setAttribute ('text',"chk" +  j[0]); 
  31.               //chk1.innerHTML  = "Default";
  32.               var lbl1   = document.createElement('label');
  33.               lbl1.setAttribute ('id', "lblDefault" );
  34.               lbl1.innerHTML =  "Default";
  35.               lbl1.style.width = "30px";
  36.               var lbl2   = document.createElement('label');
  37.               lbl2.setAttribute ('id', "lblNull");
  38.               lbl2.innerHTML =  "Nulls";
  39.               lbl2.style.width = "30px";
  40.               var lbl3   = document.createElement('label');
  41.               lbl3.setAttribute ('id', "lbl" + j[0]);
  42.               lbl3.innerHTML =  j[0];
  43.               lbl3.style.width = "125px";
  44.               var chk2   = document.createElement("input");
  45.               chk2.setAttribute ('type', 'checkbox');
  46.               chk2.setAttribute ('id', "chkNull" );
  47.               chk2.setAttribute ('name',"chkNull");
  48.               chk2.setAttribute ('text',"Null");
  49.               //chk2.innerHTML  = "null";
  50.               //txt5.value = j[0];
  51.               txt5.style.top='15px';
  52.               txt5.style.left='15px';
  53.               var newdiv = document.createElement('div');
  54.               newdiv.setAttribute('id',"divIdName");                            
  55.               newdiv.appendChild(lbl3);
  56.               newdiv.appendChild(txt5);
  57.               newdiv.appendChild(chk2);              
  58.               newdiv.appendChild(lbl2);
  59.               newdiv.appendChild(chk1);
  60.               newdiv.appendChild(lbl1);
  61.               di.appendChild(newdiv);
  62.              }
  63.             else if (j[1] == "Boolean")
  64.             {
  65.               var txt1   = document.createElement("input");
  66.               txt1.setAttribute ('type', 'radio');
  67.               txt1.setAttribute ('id', j[0]);
  68.               txt1.setAttribute ('name',j[0]);
  69.               txt1.setAttribute ('text',j[0]);
  70.               txt1.value = j[0];
  71.               //txt1.innerText = j[0];
  72.               txt1.style.top= MyHeight + 'px'; // '15px';
  73.               txt1.style.left='0px';
  74.               //rbtnfalse
  75.               var rbtn1   = document.createElement("input");
  76.               rbtn1.setAttribute ('type', 'radio');
  77.               rbtn1.setAttribute ('id',"rbtnF" +  j[0]);
  78.               rbtn1.setAttribute ('name',"rbtnF" + j[0]);
  79.               rbtn1.setAttribute ('text',"rbtnF" + j[0]);
  80.               rbtn1.value = j[0];
  81.                //chkNull
  82.               var chkNull   = document.createElement("input");
  83.               chkNull.setAttribute ('type', 'checkbox');
  84.               chkNull.setAttribute ('id',"chkNull" +  j[0]);
  85.               chkNull.setAttribute ('name',"chkNull" + j[0]);
  86.               chkNull.setAttribute ('text',"chkNull" + j[0]);
  87.              //chkDefault
  88.               var chkDefault   = document.createElement("input");
  89.               chkDefault.setAttribute ('type', 'checkbox');
  90.               chkDefault.setAttribute ('id',"chkD" +  j[0]);
  91.               chkDefault.setAttribute ('name',"chkD" + j[0]);
  92.               chkDefault.setAttribute ('text',"chkD" + j[0]);
  93.               var lbl   = document.createElement('label');
  94.               lbl.setAttribute ('id', "lbl" + j[0]);
  95.               lbl.innerHTML =  j[0];
  96.               lbl.style.width = "120px";
  97.               lbl.style.weight = "bold";
  98.               var lbl1   = document.createElement('label');
  99.               lbl1.setAttribute ('id', "lblTrue" + j[0]);
  100.               lbl1.innerHTML =  "True";
  101.               lbl1.style.width = "50px";
  102.               lbl1.style.weight = "bold";
  103.               var lbl2   = document.createElement('label');
  104.               lbl2.setAttribute ('id', "lblFalse" + j[0]);
  105.               lbl2.innerHTML =  "False";
  106.               lbl2.style.width = "50px";
  107.               lbl2.style.weight = "bold";
  108.               var lbl4   = document.createElement('label');
  109.               lbl4.setAttribute ('id', "lblD" + j[0]);
  110.               lbl4.innerHTML =  "Default";
  111.               lbl4.style.width = "50px";
  112.               lbl4.style.weight = "bold";
  113.               var lbl5   = document.createElement('label');
  114.               lbl5.setAttribute ('id', "lblN" + j[0]);
  115.               lbl5.innerHTML =  "Null";
  116.               lbl5.style.width = "50px";
  117.               lbl5.style.weight = "bold";
  118.               //txt1.style.width='10px';
  119.               //txt1.style.height='20px';
  120.               //txt5.style.visibility = 'visible'; // default anyway
  121.               var newdiv = document.createElement('div');
  122.               newdiv.setAttribute('id',"divIdName");              
  123.               newdiv.appendChild(lbl);
  124.               newdiv.appendChild(txt1);
  125.               newdiv.appendChild(lbl1);
  126.               newdiv.appendChild(rbtn1);                            
  127.               newdiv.appendChild(lbl2);  
  128.               newdiv.appendChild(chkNull);
  129.               newdiv.appendChild(lbl5);
  130.               newdiv.appendChild(chkDefault);
  131.               newdiv.appendChild(lbl4);            
  132.               di.appendChild(newdiv);
  133.               txt1.onclick=function() { if (this.checked==true) { this.checked = false} else {this.checked =true} }
  134.  
  135.             }
  136.       }
Mar 19 '09 #2
acoder
16,027 Expert Mod 8TB
I think you'll have better luck asking the .NET experts - moved to ASP.NET.

PS. please use [code] tags when posting code. Thanks.
Mar 19 '09 #3
@omlac
I have not used VB in a while, but I dont think the above will work as forms cannot be used on a web program. If anything, the message box would pop up on the server and not on the clients browser. I think you can use Response.Write (ctr.ID or whatever) in the code behind. You can copy the code into your aspx page and use "Alert(ctl.ID)".
Mar 19 '09 #4
Frinavale
9,735 Expert Mod 8TB
What are you trying to do here:
Expand|Select|Wrap|Line Numbers
  1.     Windows.Forms.MessageBox.Show(ctr.ID)
This will not work. It will attempt to display a message box on the server but of course there is no way for the application to do this so...What do you want to do?

You should consider changing your <div> into a Panel.
A Panel is rendered as a <div> in the web browser...

However I don't know how this is going to help you in the long run. It looks like you are dynamically creating HTML input elements using JavaScript.

These will not be accessible in your server code.

You should probably check out this article on how to use dynamic controls in asp.net....
Mar 19 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Pat Sagaser via .NET 247 | last post by:
I'm using a repeater with a dynamic template. I don't know the fields to display (or how many) until runtime. I have everything working except for linking Button events to the repeaters ItemCommand...
2
by: trank | last post by:
I created some checkboxes(<input type=checkbox>) dynamically,and then I'd like to access these checkboxes in code behind using C#. For they are not standard controls like Windows Checkbox, I can't...
3
by: Mr Newbie | last post by:
I am messing around with Web User Controls at present and (think) I have discovered the following. 1.) The identifier for the control in the code behind must match the ID for the control on the...
5
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I...
4
by: Boris Yeltsin | last post by:
OK, on my Master Page I have a control: <a id="hypTabAccount" href="#" runat="server">Account</a> Now, in the code-behind (Root.master.vb) I can refer to it simply thus: ...
2
by: WolfyUK | last post by:
Hello, I have a standard asp:DataGrid called CasesGrid that I wish to write my own paging controls for. The aim is to get something like the following rendered to screen: << First < Previous...
0
by: Emir | last post by:
Hi guys.. Is there a way I can set a procedure from codebehind to be called by a dynamic control? like if i am calling a javascript code i would add this code to the page_load: ...
2
by: germ | last post by:
I am moving a web application from 1.1 to 2.0 This site builds pages dynamically as : PlaceHolder.Controls.Add(LoadControl("~/Controls/Ctl1.ascx")); Everything is working fine as long as the web...
1
by: =?Utf-8?B?bWFya203NQ==?= | last post by:
I have a simple page i'm trying to do dynmaically.. i have a page called submitcomments.aspx with the .cs codebehind.. before i created everything in design view.. now i've ripped that out and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.