tags:

views:

36

answers:

3

So I was told the following would not be possible:

I have a aspx page that has a number of dropdowns. Each dropdown is set with either a class=leftcolumn or class=rightcolumn.

I need to assign an attribute:

propertyID.Attributes["nameOfAttribute"] = "false";

But instead of manually writing out each controlID and setting its attribute with the line above, I had hoped there was a way to go through and set the attribute on each control ID if it had class=leftcolumn.

This is something I know is possible to do through JQuery easily, but I need it on the code behind during load.

Thanks,

A: 

I'm not familiar enough with JQuery to write a sample of it, but you could always register a startup script in your code behind to execute when the page loads.

string myJQueryString = ; //some jquery script to set your variables
this.ClientScript.RegisterStartupScript(typeof(MyPage), "key", myJQueryString);
Steve Danner
A: 

As Steve said you can do it easily with JQuery javascript library first your should add a refrence of this library to you aspx pages then


$("select[class=leftcolumn]").each(function(index, value) {

   // You are selecting all of the dropdowns with the class attribute equal to (leftcolumn)
$(value).attr("yourCustomAttribute") = someValue;

});
Ehsan
A: 

I guess I didn't specify clearly in my question so I am answering my own so I can ask again in a completely new thread - but I want to do this in C# in the code behind, not using JQuery.

pghtech