dropdownlist value javascript Request.Form

In c#, in the page load, I want to add the below onchange event to a dropdownlist. I need to pass the selected value of the dropdownlist to the javascript function.

I want this to work without a postback, so I am pretty sure I need to use something like Request.Form["selectStyle"], but nothing comes back. As you can see I've added alerts to help me see what is coming back and the first one returns the right value, but the other 3 that can be used on the server side return an empty alert.

selectStyle.Attributes.Add("onchange", "alert(document.getElementById('selectStyle').value); alert(" + Request.Params["selectStyle"] + "); alert(" + Request.Form["selectStyle"] + "); alert(" + Request["selectStyle"] + "); showPreview('" + Crypto.EncryptInt(Convert.ToInt32(selectStyle.SelectedValue)) + "');");      }      
GeznaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

viralypatelCommented:
try this

var categoriesArray = TrendCategoriesHolder[intTrendIndex];
for ( i = 0; i <= categoriesArray.length - 1; i++)
{ var categoriesObject = categoriesArray[i];
var categoriesText = categoriesObject[0];
var categoriesValue = categoriesObject[2];
ddlTrendCategory.options[i] = new Option(categoriesText,
categoriesValue);
}
var ddlTrendType = document.getElementById("ddlTrendType");
ddlTrendCategory.options[ddlTrendCategory.options.length] = new
Option("All Categories", 0);
0
steveberzinsCommented:
I'm completely confused as to what you're trying to do.

It looks to me like you are completely confused as to the lifecycle of an .aspx page, and the difference between client vs. server side code.

I think a little more detail, maybe post your page .aspx and .cs files code, and what you envision the 'lifecycle' of this page to be, if the page is large, just strip out all the other garbage, but what you expect to be dealing with for this select control, and those directly related to this piece of functionality to are trying to create.
0
mirmansoorCommented:
put this in ur page_load
selectStyle.Attributes.Add("onchange", "javaScriptFunction(this);");
the "this" keyword will give u a reference to the dropdown on the client side... then in ur javascript function will look somethin like this
function javaScriptFunction(dd)
{
alert(ddl.options[ddl.selectedIndex].value);
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GeznaAuthor Commented:
mirmansoor,

This would work, except I need to run the Crypto.EncryptInt() function on the selected value.

Any suggestions? Obviously the below doesn't work, but something like it?

alert( <%Crypto.EncryptInt(%> ddl.options[ddl.selectedIndex].value <%);%>);
0
steveberzinsCommented:
you can't run (in a web application) c# code in the browser, on the client.

again, I don't think you understand the difference between code running on the client, and the server, and the lifecycle of your page...if you don't post back, or call somehow, code that runs on the server, you can't do what you want to do, If I'm understanding what you're trying to do anyway...

if you need to use C# functions from your client side code, you need to either live with postbacks, or look into using something like AJAX, either writing it yourself, or if you are using ASP.NET 2.0, look into ASP.NET AJAX, which will do this for you by just decorating your page with some special controls, usually just update panels, to wrap the part of the form you want to manipulate, and it will look like it is not posting back, but you can run server side code, and your page will 'look' like it is not updating from a postback, even though it is... it really is a pretty cool hack of ASP.NET, and how they make it work, with almost no effort on your part, you can make a page that looks like it is updating in place, client/server like, but it will actually be calling server side code, and only updating the parts of the page you want, with server side code, and leaving all the rest alone...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.