1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP.NET: calling the "ButtonClick" function without clicking the button

Discussion in 'C#' started by alanX, Jul 13, 2006.

  1. #1
    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)
    {
    .....
    }

    SEMrush
    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?
     
    alanX, Jul 13, 2006 IP
    SEMrush
  2. fhirzall

    fhirzall Guest

    Messages:
    124
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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.
     
    fhirzall, Jul 13, 2006 IP
  3. alanX

    alanX Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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".
     
    alanX, Jul 13, 2006 IP
  4. benjymouse

    benjymouse Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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);
     
    benjymouse, Jul 14, 2006 IP