6

I want to call two functions on button click I tried like this

 <asp:Button ID="Button2" runat="server" Font-Bold="False" onclick="tableShow();Unnamed1_Click" Text="Search" 
         Width="63px">
2
  • What kind of thing do you want to achieve by doing so? It sounds insane to me. You can call one function then inside of that function you can call other function. Commented Aug 15, 2012 at 4:43
  • @Zaksh i want to call 1 more js function to hide/unhide table on the same click. Commented Aug 15, 2012 at 4:47

3 Answers 3

17

OnClick is a server side event. Hence you can assign one method and from that method make a call to other method as below.

In asp markup

<asp:Button ID="Button2" runat="server" Font-Bold="False" onclick="Unnamed1_Click" 
 Text="Search" Width="63px">

In code behind

protected void Unnamed1_Click(object sender, EventArgs e)
{
    this.tableShow();
    //Do your actual code here.
}

UPDATE

If tableShow is a javascript method then you can use the below markup

<asp:Button ID="Button2" runat="server" Font-Bold="False" 
 OnClientClick="tableShow();" onclick="Unnamed1_Click" Text="Search"
 Width="63px">
Sign up to request clarification or add additional context in comments.

1 Comment

it works exactly i want but as i have no reputation score so i cant vote for your answer.
1

you can use the method inside method to do this. First do this

<asp:Button ID="Button2" runat="server" Font-Bold="False" onclick="Unnamed1_Click" Text="Search" 
         Width="63px">

then in code behind

protected void Unnamed1_Click(object sender, EventArgs e)
{
    //call another function here
}

Comments

0

Another option is to use the onclientclick event which allows you to run a JS function w/o a server interaction.

<asp:TemplateField>
    <FooterTemplate>
        <asp:Button ID="btnAdd" runat="server" Text="Add" onclick="btnAdd_Click" OnClientClick="javascript:ResetSaveFlag()"/>
        <asp:Button ID="btnClear" runat="server" Text="Clear" OnClientClick="javascript:ResetSaveFlag(); javascript:clearEntries(this)"/>
    </FooterTemplate>
    <ItemTemplate>
        <asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="Delete" 
            onclick="btnDelete_Click" 
            CommandArgument='<%# Eval("partNumber") + "," + Eval("warehouseLocation") %>' 
            UseSubmitBehavior="False"/>
    </ItemTemplate>
</asp:TemplateField>

In the first button (adds a new row to the table), I have a server side onclick="btnAdd_Click" as well as a client side OnClientClick="javascript:ResetSaveFlag()".

The second button (clears a row and sets a "clean" flag so onbeforeunload won't run), I'm not using any server side code, just the client side OnClientClick="javascript:ResetSaveFlag(); javascript:clearEntries(this)". The first one clears the "dirty" flag and the second one clears the row of any entries.

If anyone's interested I can post the clean & dirty flag JS, but it didn't really seem germane to the original question.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.