Click here to Skip to main content
15,914,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have to fire click event of button by code at runtime.
I cannot drectly use btn_click event because it is not accessible where I want to fire event.

So I try PerformClick method.
it works at first time but I doesbt do anything at second call.
I guess I should do something between two call of PerformClick.
Have any idea?
Posted
Comments
Karthik Harve 5-Dec-11 6:57am    
explain with some code..
Anuj Banka 5-Dec-11 7:11am    
Show us code so that we can understand your problem

Hi,

you can create click event like,

C#
btn_Click += new ButtonClick(callingFunctionName);


hope this will help you,

thanks
-amit.
 
Share this answer
 
Comments
fadime 5-Dec-11 7:46am    
I know I can but
there is already click event function fro this button at another dll.
Actually my button at a tabpage and this tabpage is generated by another dll(mentioned above) , and I just call this dll and take generated tab page and add to my form. So I cant call private click method. I can call PerformClick but at second call of performclick , it do nothing.
AmitGajjar 5-Dec-11 7:50am    
If you are working in asp.net then there may be issue of page postback event. let me know if you are working on wpf, windows , asp.net ?
fadime 7-Jan-12 15:28pm    
windows
AmitGajjar 8-Jan-12 23:15pm    
then above code should work fine ? is there any problem with given code ?
XML
<html xmlns="http://www.w3.org/1999/xhtml">
        <head>
    <title>Untitled Page</title>
    <script type="text/javascript">
    function clk()
    {
    document.getElementById('Button1').click();
    }
    </script>
       </head>
<body onload="clk();">
<div>
    <form id="form1" runat="server">

    <div>
        <asp:Button ID="Button1" runat="server" Text="Choose file.."
            onclick="Button1_Click"  />
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>

    </form>
    </div>

</body>
</html>


In the Above code i have called a java script function which perform click event of Asp button during page load.

I hope this may help u...
 
Share this answer
 
I bet if you stopped to used the debugger once in a while, you could detremine what's happening on your own.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900