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[i];
-
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} }
-
-
}
-
}
4 4741
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[i];
-
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} }
-
-
}
-
}
I think you'll have better luck asking the .NET experts - moved to ASP.NET.
PS. please use [code] tags when posting code. Thanks.
@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)".
What are you trying to do here: -
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....
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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:
...
|
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...
|
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:
...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |