hi,
can I open a dropdownlist of asp.net by server code?
(on asyncPostBack)
tanx.
sara.
Asp - open dropdownlist by code
6 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted Jul 2, 2009, 3:53 AM EDT
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted Jul 2, 2009, 4:11 AM EDT
Here I am showing it onmouseover.
<asp:DropDownList id="DropDownList1" onmouseover="openListElement(this);" onmouseout="closeListElement(this);" runat="server">
<asp:listitem value="">Select one</asp:listitem>
<asp:listitem value="1">Item 1</asp:listitem>
<asp:listitem value="2">Item 2</asp:listitem>
<asp:listitem value="3">Item 3</asp:listitem>
<asp:listitem value="4">Item 4</asp:listitem>
<asp:listitem value="5">Item 5</asp:listitem>
<asp:listitem value="6">Item 6</asp:listitem>
</asp:DropDownList>
<script type="text/javascript">
<!--
function openListElement(elementRef)
{
elementRef.size = elementRef.options.length;
}
function closeListElement(elementRef)
{
elementRef.size = 1;
}
// -->
</script>
You also can refer the following thread:
http://forums.asp.net/p/1118333/1745578.aspx
sara shats9 pointsPosted Jul 2, 2009, 4:42 AM EDT
it's not going to client side after, I tryed to put ScriptManager.RegisterStartupScript, but it didnt do it
(maybe its becose it's AsyncPostBack?)
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted Jul 2, 2009, 5:00 AM EDT
Use the following code in pagebehind where you want to call the function and write the javascript function in to of the page as it is shown below.
Page.ClientScript.RegisterStartupScript(this.GetType(), "", " openListElement(this);";", true);
// pass the instance of dropdownlist in onclick event
%@ Page Language="C#" AutoEventWireup="true" CodeFile="Reservation.aspx.cs" ClientTarget="uplevel"
Inherits="New_Reservation" EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>New Page</title>
<script type="text/javascript">
function openListElement(elementRef)
{
elementRef.size = elementRef.options.length;
}
</script>
</head>
<body bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0">
<form id="frmReservation" runat="server">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr valign="top">
<td align="right">
</td>
</table>
</form>
</body>
sara shats9 pointsPosted Jul 2, 2009, 5:35 AM EDT
Page.ClientScript.RegisterStartupScript(This.GetType(), "", "openListElement(" + ddlUnder.ClientID + ");", True);
and put debugger on the javascript function but it didn't get in.
any idea?
amit9 pointsPosted Sep 26, 2014, 1:09 AM EDT
1 short reply
sara shats9 pointsPosted Jul 2, 2009, 4:00 AM EDT