i have some dynamic controls that i add to a webform (actually, i dynamiclly
build a table and add the controls to cells). some of these controls are
HtmlSelect controls with the multiple property set to true.
i have figured out how to loop through the controls on the form and find the
one i am looking for. when i go to get the values out of it, it only gives
me the fist value. for instance, if i have "a", "b", and "c", when i do the
loop through arr2 (see code below), it only has a length of 1 and it only
has the first value in the list. I need to get to all values in the
htmlselect control. how can i do this? thanks. //Paul
private void btnSaveAs_Click(object sender, System.EventArgs e)
{
....... other code
int loop1, loop2;
string paramValues = '";
System.Collections.Specialized.NameValueCollection coll;
// Load ServerVariable collection into NameValueCollection object.
coll=Request.Params;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
string s = arr1[loop1];
if(s == "cmbMediaType")
{
String[] arr2=coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
paramValues += arr2[loop2] + "|";
//Response.Write("Value " + loop2 + ": " + arr2[loop2] +
"<br>");
}
}
}
..... other code
} 4 1491
I'm missing what you're trying to do. But from looking at your code, in general,
you don't need to access the Request object to look at the posted data. Instead
use the server control itself. By ignoring the server controls you are really
not fully utilizing the entire object model of ASP.NET.
-Brock
DevelopMentor http://staff.develop.com/ballen i have some dynamic controls that i add to a webform (actually, i dynamiclly build a table and add the controls to cells). some of these controls are HtmlSelect controls with the multiple property set to true. i have figured out how to loop through the controls on the form and find the one i am looking for. when i go to get the values out of it, it only gives me the fist value. for instance, if i have "a", "b", and "c", when i do the loop through arr2 (see code below), it only has a length of 1 and it only has the first value in the list. I need to get to all values in the htmlselect control. how can i do this? thanks. //Paul private void btnSaveAs_Click(object sender, System.EventArgs e) { ...... other code int loop1, loop2; string paramValues = '"; System.Collections.Specialized.NameValueCollection coll; // Load ServerVariable collection into NameValueCollection object. coll=Request.Params; // Get names of all keys into a string array. String[] arr1 = coll.AllKeys; for (loop1 = 0; loop1 < arr1.Length; loop1++) { string s = arr1[loop1]; if(s == "cmbMediaType") { String[] arr2=coll.GetValues(arr1[loop1]); for (loop2 = 0; loop2 < arr2.Length; loop2++) { paramValues += arr2[loop2] + "|"; //Response.Write("Value " + loop2 + ": " + arr2[loop2] + "<br>"); } } } .... other code }
well, the issue is that I am creating the controls dynamically, so I dont
have access to them in the traditional way.
in other words when i add a control i (well, actually the developer before
me) do something like:
HtmlTableCell tc;
HtmlTableRow tr;
HtmlSelect selMulti;
....init code is here
tc = new HtmlTableCell();
tc.Width = "10%";
selMulti = new HtmlSelect();
selMulti.Multiple = true;
selMulti.ID = classPopulatedFromDB.ControlName;
selMulti.Items.Capacity = 10;
selMulti.Size = 3;
tc.Controls.Add(PopulateMultiSelectControl(selMult i));
tr.Cells.Add(tc);
this.tableAddedAtDesignTime.Rows.Add(tr);
that is kinda what is going on in my code. So when I am in the code, I dont
even know the name of the control...so I cant do
this.ControlName.Items.....you get the point I hope. I understand that this
may not be the most elagant way of doing things, but it is the code I have
been handed and that I have to make work :) I hope this helps my post make
more sense as to what I am trying to accomplish.
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:78**********************@msnews.microsoft.com ... I'm missing what you're trying to do. But from looking at your code, in general, you don't need to access the Request object to look at the posted data. Instead use the server control itself. By ignoring the server controls you are really not fully utilizing the entire object model of ASP.NET. -Brock DevelopMentor http://staff.develop.com/ballen i have some dynamic controls that i add to a webform (actually, i dynamiclly build a table and add the controls to cells). some of these controls are HtmlSelect controls with the multiple property set to true. i have figured out how to loop through the controls on the form and find the one i am looking for. when i go to get the values out of it, it only gives me the fist value. for instance, if i have "a", "b", and "c", when i do the loop through arr2 (see code below), it only has a length of 1 and it only has the first value in the list. I need to get to all values in the htmlselect control. how can i do this? thanks. //Paul private void btnSaveAs_Click(object sender, System.EventArgs e) { ...... other code int loop1, loop2; string paramValues = '"; System.Collections.Specialized.NameValueCollection coll; // Load ServerVariable collection into NameValueCollection object. coll=Request.Params; // Get names of all keys into a string array. String[] arr1 = coll.AllKeys; for (loop1 = 0; loop1 < arr1.Length; loop1++) { string s = arr1[loop1]; if(s == "cmbMediaType") { String[] arr2=coll.GetValues(arr1[loop1]); for (loop2 = 0; loop2 < arr2.Length; loop2++) { paramValues += arr2[loop2] + "|"; //Response.Write("Value " + loop2 + ": " + arr2[loop2] + "<br>"); } } } .... other code }
Upon postback you should always recreate them (in Page_Load or override CreateChildControls).
Then you can use FindControl to locate them. I have a post here that shows
a sample: http://groups-beta.google.com/group/...ewstate&rnum=1
-Brock
DevelopMentor http://staff.develop.com/ballen well, the issue is that I am creating the controls dynamically, so I dont have access to them in the traditional way. in other words when i add a control i (well, actually the developer before me) do something like: HtmlTableCell tc; HtmlTableRow tr; HtmlSelect selMulti; ...init code is here tc = new HtmlTableCell(); tc.Width = "10%"; selMulti = new HtmlSelect(); selMulti.Multiple = true; selMulti.ID = classPopulatedFromDB.ControlName; selMulti.Items.Capacity = 10; selMulti.Size = 3; tc.Controls.Add(PopulateMultiSelectControl(selMult i)); tr.Cells.Add(tc); this.tableAddedAtDesignTime.Rows.Add(tr); that is kinda what is going on in my code. So when I am in the code, I dont even know the name of the control...so I cant do this.ControlName.Items.....you get the point I hope. I understand that this may not be the most elagant way of doing things, but it is the code I have been handed and that I have to make work :) I hope this helps my post make more sense as to what I am trying to accomplish.
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message news:78**********************@msnews.microsoft.com ...
I'm missing what you're trying to do. But from looking at your code, in general, you don't need to access the Request object to look at the posted data. Instead use the server control itself. By ignoring the server controls you are really not fully utilizing the entire object model of ASP.NET. -Brock DevelopMentor http://staff.develop.com/ballen i have some dynamic controls that i add to a webform (actually, i dynamiclly build a table and add the controls to cells). some of these controls are HtmlSelect controls with the multiple property set to true. i have figured out how to loop through the controls on the form and find the one i am looking for. when i go to get the values out of it, it only gives me the fist value. for instance, if i have "a", "b", and "c", when i do the loop through arr2 (see code below), it only has a length of 1 and it only has the first value in the list. I need to get to all values in the htmlselect control. how can i do this? thanks. //Paul private void btnSaveAs_Click(object sender, System.EventArgs e) { ...... other code int loop1, loop2; string paramValues = '"; System.Collections.Specialized.NameValueCollection coll; // Load ServerVariable collection into NameValueCollection object. coll=Request.Params; // Get names of all keys into a string array. String[] arr1 = coll.AllKeys; for (loop1 = 0; loop1 < arr1.Length; loop1++) { string s = arr1[loop1]; if(s == "cmbMediaType") { String[] arr2=coll.GetValues(arr1[loop1]); for (loop2 = 0; loop2 < arr2.Length; loop2++) { paramValues += arr2[loop2] + "|"; //Response.Write("Value " + loop2 + ": " + arr2[loop2] + "<br>"); } } } .... other code }
dang. i was hoping to avoid that because it makes this code even more
complicated :) thank you for the link. i think it will solve the problem.
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:78**********************@msnews.microsoft.com ... Upon postback you should always recreate them (in Page_Load or override CreateChildControls). Then you can use FindControl to locate them. I have a post here that shows a sample:
http://groups-beta.google.com/group/...ewstate&rnum=1
-Brock DevelopMentor http://staff.develop.com/ballen well, the issue is that I am creating the controls dynamically, so I dont have access to them in the traditional way. in other words when i add a control i (well, actually the developer before me) do something like: HtmlTableCell tc; HtmlTableRow tr; HtmlSelect selMulti; ...init code is here tc = new HtmlTableCell(); tc.Width = "10%"; selMulti = new HtmlSelect(); selMulti.Multiple = true; selMulti.ID = classPopulatedFromDB.ControlName; selMulti.Items.Capacity = 10; selMulti.Size = 3; tc.Controls.Add(PopulateMultiSelectControl(selMult i)); tr.Cells.Add(tc); this.tableAddedAtDesignTime.Rows.Add(tr); that is kinda what is going on in my code. So when I am in the code, I dont even know the name of the control...so I cant do this.ControlName.Items.....you get the point I hope. I understand that this may not be the most elagant way of doing things, but it is the code I have been handed and that I have to make work :) I hope this helps my post make more sense as to what I am trying to accomplish.
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message news:78**********************@msnews.microsoft.com ...
I'm missing what you're trying to do. But from looking at your code, in general, you don't need to access the Request object to look at the posted data. Instead use the server control itself. By ignoring the server controls you are really not fully utilizing the entire object model of ASP.NET. -Brock DevelopMentor http://staff.develop.com/ballen i have some dynamic controls that i add to a webform (actually, i dynamiclly build a table and add the controls to cells). some of these controls are HtmlSelect controls with the multiple property set to true. i have figured out how to loop through the controls on the form and find the one i am looking for. when i go to get the values out of it, it only gives me the fist value. for instance, if i have "a", "b", and "c", when i do the loop through arr2 (see code below), it only has a length of 1 and it only has the first value in the list. I need to get to all values in the htmlselect control. how can i do this? thanks. //Paul private void btnSaveAs_Click(object sender, System.EventArgs e) { ...... other code int loop1, loop2; string paramValues = '"; System.Collections.Specialized.NameValueCollection coll; // Load ServerVariable collection into NameValueCollection object. coll=Request.Params; // Get names of all keys into a string array. String[] arr1 = coll.AllKeys; for (loop1 = 0; loop1 < arr1.Length; loop1++) { string s = arr1[loop1]; if(s == "cmbMediaType") { String[] arr2=coll.GetValues(arr1[loop1]); for (loop2 = 0; loop2 < arr2.Length; loop2++) { paramValues += arr2[loop2] + "|"; //Response.Write("Value " + loop2 + ": " + arr2[loop2] + "<br>"); } } } .... other code } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Will |
last post by:
Hi all.
I'm learning VB.Net and am developing a WinForms app.
I'm trying to make an app that I will use to scan in one or more than
on image. I want to use a tabbed interface to hold each image....
|
by: theComputer7 |
last post by:
I cut down the code to make this half way understandable... I have
read Data Grid girls caution about over use of dynamic controls. I
truly believe what I am doing requires dynamically inserted...
|
by: Leo J. Hart IV |
last post by:
OK, here's another question for the experts:
I am building a multi-step (3 steps actually) form using a panel for
each step and hiding/displaying the appropriate panel/panels depending
on which...
|
by: pbb |
last post by:
I have a web page on which I dynamically create controls based on the
selection a user makes from a dropdownlist (this ddl is not dynamic).
Depending on the user's selection, the controls could be...
|
by: Diffident |
last post by:
Hello All,
I am trying to add dynamic controls onto my page and here is how I am doing
that.
I have a page which has a button called as "AddMoreControls" and in this
button's event handler I...
| |
by: Tarscher |
last post by:
hi all,
I have this seemingly simple problem. I have lost a lot of time on it
though.
When a user selects a value from a dropdownlist (static control) a
dynamic control is generated. I have...
|
by: Eniac |
last post by:
Hi,
I've been working on a custom user control that needs to be modified
and the validation is causing me headaches.
The control used to generate a table of 4 rows x 7 columns to display
all...
|
by: MaryamSh |
last post by:
Hi,
I am creating a Dynamic Search in my application.
I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove)
By pressing Add button...
|
by: MaryamSh |
last post by:
Create Dynamic Dropdownlist Controls and related event
--------------------------------------------------------------------------------
Hi,
I am creating a Dynamic Search in my application.
I...
|
by: englishman69 |
last post by:
Hello,
I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |