Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

No Click Button Clicks

I have an increasingly complex web form littered with panels, buttons text boxes, and a plethora of other controls.

The page shows panels, and selects dropdowns based on various user inputs.

I have reached a stage where it would be convenient for me to be able to "fake" a user clicking a button in my code.

.net does not seem to have a .clickme function I can call on my buttons. Is there any way to do this programmatically?

Aidan
Tuesday, July 27, 2004

Put the code behind the button into a function. Then you can call the function either when the button is pressed or somewhere else such as Page Load

IdleCoder
Tuesday, July 27, 2004

The thing is that the sub the button-click points to is used by a number of buttons and the buttons "commandname" is used to decide what action to take.

I suppose I could pass the commandname as a string into my new sub, then send an appropriate command through my "spoof" click.

That is not going to do anything for the readability of my code though!

Aidan
Tuesday, July 27, 2004

Bah, I have just noticed that when i change a  dropdown's index using  ".SelectedIndex = " the SelectedIndexchanged sub does not fire!

A lot of things with ASP.NET don't behave as i expect!

On a side note, is there somewhere on the net more appropriate for my type of problem, which are generally born from a lack of understanding of the .net framework, rather than more technical (i.e. interesting) problems?

Aidan
Tuesday, July 27, 2004

Set AutoPostBack="true" in the DropDown declaration - that will cause a postback to - um - post back every time a new value has changed.

Greg Hurlman
Tuesday, July 27, 2004

I should start reading full posts before I respond... damn you JoS "no quoting" rule!

http://www.asp.net/forums/ is a good place to seek out ASP.Net support at all levels, along with the AASp.Net newsgroups (http://groups.google.com/groups?q=group%3Amicrosoft.public.dotnet.framework.aspnet&hl=en&lr=&ie=UTF-8&c2coff=1&sa=N&tab=wg)

Greg Hurlman
Tuesday, July 27, 2004

Thanks for the links, I will try asp.net forums.
I only have google.groups for newsnet access, and that has a 4 hour wait time between posting and seeing the post. I have usually worked out the problem by then. Maybe a good thing :D

Re: the drop down post back.

Auto postback is set to true, however when I programmatically change the selected index I am not getting the sub run.  If i manually make a selection then it works as you would expect.

The sub is quite simple, so maybe I will just pull this out into another one and call that. This feels like a hack though...

Aidan
Tuesday, July 27, 2004

*  Recent Topics

*  Fog Creek Home