The idea of setting client events in DropDownList is as follows: The dropdownlist Client

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.