The idea of setting client events in DropDownList is as follows: The dropdownlist Client
Suppose: the data source control GrdiView, without refreshing UpdatePannel, prompts UpdateProgress in a friendly way, And DropDownList in a paging drop-down box.
Generally, the page of the Gridview contains a linkbutton or button. In this case, if you want to display the UpdateProgress prompt, it is very easy to hide the GridView first, and then add an OnClientClick to it!
In the onchange event of DropDownList:
function selectChange() { if ($("select option").is(":selected")) { $("#btn11").click(); } }
Jump:
<asp:DropDownList ID="ddlNeedPage" runat="server" AutoPostBack="true" onchange="return selectChange();"> </asp:DropDownList>
function clearData() { //$("#<%=_gvGuest.ClientID %>").empty(); $("#_gvGuest").empty(); //$("#<%=lblMessage.ClientID %>").hide(); $("#lblMessage").hide(); }
<Asp: LinkButton ID = "lnkFirstPage" runat = "server" <span style = "color: # ff0000;"> OnClientClick = "return clearData (); "</span> CommandName =" Page "CommandArgument =" First "Enabled =" <% # (GridView) Container. parent. parent ). pageIndex! = 0%> "> page 1 </asp: LinkButton>
But the DropDownList does not have an OnClientClick event. What should I do?
Because the Button mentioned above has Onclientclick, we can think of using the Button to convert it !!!!
Solution:Put a hidden button on the page:
<asp:Button ID="btn11" runat="server" CssClass="btnPage"Style="display: none;" OnClick="btn11_Click" OnClientClick="return clearData2();"/>
Then, in the OnClientClick event, assign the value of the drop-down box to a hidden field.
function clearData2() { var hidDDL = $("#_gvGuest_ddlNeedPage").val(); $("#hidNeedPage").attr("value", hidDDL); $("#_gvGuest").empty(); $("#lblMessage").hide(); }
In the click event, set the PageIndex of _ gvGuest to the value of the hidden field!
protected void btn11_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(hidNeedPage.Value)) { _gvGuest.PageIndex = Convert.ToInt32(hidNeedPage.Value); BindData(); } }
The basic idea is implemented. I believe that through the above step-by-step implementation, you will also have a general understanding of how to set client events in DropDownList. I hope this article will truly help you.