simulate button click in C#

M

Martin Dechev

Hi, Max,

Can you explain what are you trying to do? You can call the method that
handles the Click event at any point supposing that you have instance of the
class in which the method is member:

if(someCondition)
Button1_Click(null, null);

Greetings
Martin
 
G

Guest

Thanks Martin

What I am trying to do i

When user clicks Button1 then some attributes are added to Button2 which then should invoke VB Script function
I need all this done by just clicking Button1. I have this webform where user can search adequate conference rooms for the particular meeting. When user completes filling criterias in form, the code I wrote searches adequate conferense roomss' names in SQL Server and then those conference rooms and criterias are passed to my VB Script as parameters. The VB script then adds adequate conference rooms as resources in Outlook. So I need Button1 to Add script attributes to Button2 (Because I am using parameters in VB script) and then Button2 should run VB script. I tried to call Button2's Click method (Button2_Click(null, null)), but id did not run the VB script, so user needs to actually click Button2 also, which is bad. Can I somehow work around this

Max
 
M

Martin Dechev

Hi, Max,

You can add client-side script to the page that will call Button2.Click() or
call directly the VBScript function that handles the click. Use the
RegisterClientScriptBlock or RegisterStartupScript methods on the Page
class.

The only way to call a client-side function is to add client-side code to do
this.

Hope this helps
Martin
Max said:
Thanks Martin,

What I am trying to do is

When user clicks Button1 then some attributes are added to Button2 which
then should invoke VB Script function.
I need all this done by just clicking Button1. I have this webform where
user can search adequate conference rooms for the particular meeting. When
user completes filling criterias in form, the code I wrote searches adequate
conferense roomss' names in SQL Server and then those conference rooms and
criterias are passed to my VB Script as parameters. The VB script then adds
adequate conference rooms as resources in Outlook. So I need Button1 to Add
script attributes to Button2 (Because I am using parameters in VB script)
and then Button2 should run VB script. I tried to call Button2's Click
method (Button2_Click(null, null)), but id did not run the VB script, so
user needs to actually click Button2 also, which is bad. Can I somehow work
around this?
 
G

Guest

Please, could you tell me, how can I call directly the vb script after I registered it with RegisterClientScriptBlock? Sorry for asking so simple questions, I started developing with ASP.NET just few weeks ago.

thanks

Max
 
M

Martin Dechev

The following will call the function immediately after the page is loaded:

string script = @"<SCRIPT FOR=window EVENT=onload LANGUAGE="vbscript">" +
Environment.NewLine;
script += @" ' Do something, i.e. call the Button2_Click function" +
Environment.NewLine;
script += string.Format(@"Button2_Click {0}, {2}{3}", param1, param2,
Environment.NewLine);
script += @"</SCRIPT>";
RegisterClientScriptBlock(script, "Call Button2_Click");

Hope this helps
Martin
Max said:
Please, could you tell me, how can I call directly the vb script after I
registered it with RegisterClientScriptBlock? Sorry for asking so simple
questions, I started developing with ASP.NET just few weeks ago.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top