Thursday, March 22, 2012

calling javascript on OnSelectedIndexChanged of a drop downlistbox

I have a dropdownlist and a text box.

Once i select the item on a dropdownlist, the control should skip to text box.

Here is the code and i get the error.

'onFocus' is not a member of 'ASP.test_aspx'.

can u plz help me out.

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

<scriptlanguage="javascript">

function onFocus()

{

var control = document.getElementById("TextBox1");

if( control != null ) control.focus();

}

</script>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:DropDownListID="DropDownList1"runat="server"Width="161px"OnSelectedIndexChanged="onFocus()">

<asp:ListItem>Javed</asp:ListItem>

<asp:ListItem>Abid</asp:ListItem>

<asp:ListItem>sajid</asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:DropDownList>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox></div>

</form>

</body>

</html>

The reason you are getting this type of error is because you try to associate (link) JS function with ASP event. when you declare event such as OnSelectedIndexChanged ASP searchs the code behind or C#/VB section for a handler to invoke once this event fires.

A very simple way to diffrentiate between HTML DOM events and ASP events is the case. Note that ASP is always MixCase.

sql

No comments:

Post a Comment