Client side code to pass values to server side variable?

Hi there,

I have ListBox_SelectedTextChanged() method that creates another list box in the runtime as follows:

// Get Action Level List

lbxActionLevel = new ListBox();lbxActionLevel.ID = "ddlA" + i.ToString();

lbxActionLevel.Width = 100;

lbxActionLevel.Rows = 2;

SqlDataReader dr = new BusinessLogicLayer().bllGetActionLevels();

lbxActionLevel.Items.Clear();

while (dr.Read())

{

ListItem lAction = new ListItem();

lAction.Text = dr.GetString(1).Trim();

lAction.Value =
Convert.ToString(dr.GetInt32(0));

lbxActionLevel.Items.Add(lAction);

lbxActionLevel.SelectedIndex = 0;

}

I guess because this lbxActionLevel object is generated on the fly, I can't get the selection values once I click the "Done" button. I don't want the lbxActionLevel to do autopostback bacause for some reason most of the user input gets wiped out. Is there a way to get the user selection collected on the client side (javascript) and pass it to the C# code?

Thanks,

EJM

 


Software engineering is a team sport.
0
EJM
3/13/2008 4:57:06 PM
📁 asp.net.presentation-controls
📃 72751 articles.
⭐ 3 followers.

💬 3 Replies
👁️‍🗨️ 1386 Views

use Asp HiddenField control and assign the value coming from your JS method after that you can now access the Value stored in your HiddenField in the server

 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
3/13/2008 5:16:48 PM

I understand the use of HiddenFields, but in this case I don't know what the user is going to select before the page is rendered. And for some reason when the form fields are generated on the fly, it works differently as when they are created in the design time. I'd like to also know what that is.

thanks,

EJM


Software engineering is a team sport.
0
EJM
3/13/2008 5:32:32 PM

since you are creating the controls dynamically then please refer to the link below on how to handle dynamically created controls


http://www.singingeels.com/Articles/Dynamically_Created_Controls_in_ASPNET.aspx

http://support.microsoft.com/kb/317515


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
3/13/2008 5:37:21 PM