views:

365

answers:

3

I have a Wizard control on my ASP.NET web form. I am setting the default button on each step in the ApplicationWizard PreRender event in code-behind like so:

Page.Form.DefaultButton = ApplicationWizard.FindControl("StepNavigationTemplateContainerID").FindControl("StepNextButton").UniqueID;

This is working perfectly, but when I ajaxify the Wizard control it does not work. The Default button is set to the Control I specify when initally loading the form (StartNextButton) but does not update to StepNextButton on other steps. What am I doing wrong?

+1  A: 

Try the ScriptManager.SetFocus.

Artem K.
A: 

Is there a reason you want to do this on PreRender as opposed to after? If you are only trying to set focus after a post, my inclination would be to use javascript to set focus() using document.onload event or something similar. I think this is what Artem was suggesting.

jimyshock
A: 

What is the definition of a default button? If it's a button, which should be called when you are in a text form field (input type=text) and press enter, then in every browser it is a first submit or image button in the form (input type=submit|image) if exist.

What you can do, is to add a client script to all controls, to which such rule as submit form on [enter] apply (like on input type="text").

Server side sample (can be used in Form_Init) just for an idea:

SomeTextBox.Attributes.Add("onkeydown",
    "if((event.keyCode&&event.keyCode==13)){" +
    Page.ClientScript.GetPostBackEventReference(StepNextButton, "") +
    ";return false;}" +
    "if((event.keyCode&&event.keyCode==27)){" +
    Page.ClientScript.GetPostBackEventReference(CancelButton, "") +
    ";return false;}");

keyCode==13 is an Enter key
keyCode==27 is an Escape key

Viktor Jevdokimov