DropDownList Thoughts on Setting Client Events

  • 2021-07-06 10:40:36
  • OfStack

Assumptions: Data source control GrdiView, no refresh UpdatePannel, friendly reminder UpdateProgress, paging drop-down box DropDownList

1 general situation: Gridview paging has linkbutton or button, so if you want to make UpdateProgress prompt, very simple, first let GridView hide, and then add an OnClientClick to it!
In the onchange event of DropDownList:


function selectChange() { 
      if ($("select option").is(":selected")) { 
        $("#btn11").click(); 
      } 
    } 

Jump to:


 <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 %>"> No. 1 1 Page </asp:LinkButton> 

But DropDownList has no OnClientClick event. What should I do?

Because it is said above that Button has Onclientclick, we can think of using Button to convert 1! ! ! !

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 assign the value of the drop-down box to a hidden field in the OnClientClick event


function clearData2() { 
      var hidDDL = $("#_gvGuest_ddlNeedPage").val(); 
      $("#hidNeedPage").attr("value", hidDDL); 
      $("#_gvGuest").empty(); 
      $("#lblMessage").hide(); 
    } 

Then set the PageIndex of _ gvGuest to the value of the hidden domain in the click event!


protected void btn11_Click(object sender, EventArgs e) 
    { 
 
      if (!string.IsNullOrEmpty(hidNeedPage.Value)) 
      { 
        _gvGuest.PageIndex = Convert.ToInt32(hidNeedPage.Value); 
        BindData(); 
      } 
    }

The basic idea has been realized. I believe that through the above step-by-step implementation, everyone has a general understanding of DropDownList setting client events. I hope this article can really help everyone.


Related articles: