Simulating button click 
Author Message
 Simulating button click
I have a web form page with textboxes and a button.

Is there a way to 'simulate' clicking the button with code so the result is
exactly as if someone clicked the button with their mouse?

Thanks



Tue, 08 Feb 2005 04:48:07 GMT  
 Simulating button click
Il cervello cattivo di Craig produceva il seguente:

Quote:

> I have a web form page with textboxes and a button.

> Is there a way to 'simulate' clicking the button with code so the result is
> exactly as if someone clicked the button with their mouse?

Just put the code that is executed when the button is clicked in an extra
procedure and then call it to simulate the click.
Example:

Private Sub btnWhatever_Click (bla) Handles btnWhatever.Click
    buttonClicked()
End Sub

Private Sub simulateClick
    buttonClicked()
End Sub

Public Sub buttonClicked
    ' put the code here that is executed when the button is clicked
End Sub

--
Tenchi (remove 'spam.be.gone' for emails)

My VB.net Download-Manager (Version 1.12.1400)
Homepage: http://home.arcor.de/minako.aino/DownloadWonder/
Mailing list: http://de.groups.yahoo.com/group/dw-net/



Tue, 08 Feb 2005 05:49:47 GMT  
 Simulating button click
Will this do a POST for a form?


Quote:
> Il cervello cattivo di Craig produceva il seguente:

> > I have a web form page with textboxes and a button.

> > Is there a way to 'simulate' clicking the button with code so the result
is
> > exactly as if someone clicked the button with their mouse?

> Just put the code that is executed when the button is clicked in an extra
> procedure and then call it to simulate the click.
> Example:

> Private Sub btnWhatever_Click (bla) Handles btnWhatever.Click
>     buttonClicked()
> End Sub

> Private Sub simulateClick
>     buttonClicked()
> End Sub

> Public Sub buttonClicked
>     ' put the code here that is executed when the button is clicked
> End Sub

> --
> Tenchi (remove 'spam.be.gone' for emails)

> My VB.net Download-Manager (Version 1.12.1400)
> Homepage: http://home.arcor.de/minako.aino/DownloadWonder/
> Mailing list: http://de.groups.yahoo.com/group/dw-net/



Tue, 08 Feb 2005 06:44:33 GMT  
 Simulating button click
Hi,

I think this is what your after..

Have a button and a textbox on your webform. Pressing the Enter key on
the textbox will force a button click event to fire on the
imagebutton.

( linewrap may make this look odd )

<asp:textbox id="txtKeywords" runat="server" Width="273px"
onkeydown="editKeyDown(event);"></asp:textbox>&nbsp;<asp:imagebutton
id="btnSearch" runat="server" ToolTip="Search" ImageAlign="AbsMiddle"
ImageUrl="gfx/search-2.gif"></asp:imagebutton>

Add a linkbutton to your form as this will generate the code needed to
perform a postback ( if you dont already have a control on the form
that does this )

<asp:LinkButton id="tmpBtn" runat="server"
Width="0px"></asp:LinkButton>

Set the width to 0 so we dont see it on the rendered page.

Add some javascript to the page that is called when the user presses a
key on the edit box.

function editKeyDown(e)
{              
        if ( e.keyCode == 13 )
        {                              
                e.keyCode = 0;
                e.returnValue = false;
                e.cancelBubble = true;                                          
                __doPostBack('btnSearch','');                                  
        }

Quote:
}

The code calls the postback function for btnSearch to simulate the
button click.

Hope that makes some sense ( I did write a long message and bigger
example but the browser crashed and I didnt have the time to type it
all back in again.. )

Peter.

Quote:

> I have a web form page with textboxes and a button.

> Is there a way to 'simulate' clicking the button with code so the result is
> exactly as if someone clicked the button with their mouse?

> Thanks



Tue, 08 Feb 2005 16:21:47 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Simulate button click?

2. Simulating button-click events using code

3. simulating cmd button click event

4. Simulating toolbar button click through menu item?

5. Simulate clicking a toolbar button

6. simulate a click with the left button in a listview

7. Code to simulate mouse button clicks

8. simulate click on a button ?

9. VBScript for simulating clicking the stop button on IE toolbar

10. Simulating clicking on the home button?

11. using code to simulate mouse button clicks

12. How to simulate clicking a button on browser

 

 
Powered by phpBB® Forum Software