Hi all, i have created "ButtonClick" function using C# and ASP.NET as following: <asp:Button ID="Search" Text="Search" onClick="Searching_Data" runat="server" /> private void Searching_Data(Object sender, EventArgs E) { ..... } But i want to call the function without clicking the button. so i can call function anywhere between the <script> ... </script> Can anyone help me?
So you basically just want to be able to call that code in other places in your code? If so, just do this. private void Search(Object sender, EventArgs e) { //put code used to search here } then in your onclick event which is private void Searching_Data(Object sender, EventArgs E) { Search() } then anywhere else in your code you can just call Search() and it'll execute the code.
Thank for your reply; In fact, the program is as following: private void DataGrid_Page(Object sender,DataGridPageChangedEventArgs e) { try { DataGrid1.CurrentPageIndex = e.NewPageIndex; Searching_Data();<---error } catch (SystemException d) { Message.Style["color"] = "red"; Message.Text = d.ToString(); } } Q1: I don't know how to call the "ButtonClick" function as there are two parameters in Searching_function(p1,p2) Q2: How to restore the DataGrid1.CurrentPageIndex to be "1".
the two parameters are the "sender" of the event (i.e. the button clicked) and some eventargs. If your method does not use them, simple call by Searching_Data(this, EventArgs.Empty);