webform and C# code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

All,

I have a dropdown list box that when a user clicks on it i would like to run
some code within the webform1.aspx

I have the following

<asp:dropdownlist id="ddlLocation" OnClick="check_click" runat="server">

check_click is defined as follows within the header tag

<script runat=server >

void check_click(Object sender, EventArgs e)
{
......
}

</script>

But when the user click on the drop down box I get an exception saying it
cant find check_click what is wrong?

Thanks
Msuk
 
There is no server side event for a Click for a DropDownList. Are you
wanting to look at the value when the Selection has changed? You will want
the server side event "OnSelectedIndexChanged".

If you want your "check_click" code to run as soon as the selection has
changed, (without hitting a button for a postback) you will need to set
AutoPostBack="True" on your control.

HTH,

bill
 
The dropdownlist doesn't have an onClick event...so what's happening is the
line:

<asp:dropdownlist id="ddlLocation" OnClick="check_click" runat="server">

is turning into:

<select onClick="check_click" id="ddlLocation"
name="ddlLocation">...</select>

as you can see, it's being rendered as a javascript event. The short answer
is non-existing properties get rendered as html attributes. Since onClick
isn't a valid DropDownList (server-side) property, it's being rendered as-is
as an HTML attribute..which makes it a javascript (client-side) event.

Karl
 
Back
Top