Execute Javascript code on a navigation button in Wizard Control.

As you may know the wizard control, provided by ASP.NET 2.0, allows us to create a navigation system with multiple steps. if you are not familiar with the wizard control please check below link

Wizard Control in ASP.NET 2.0

Once you create a wizard step, you can set the StepType to dynamically create the proper navigation buttons. For this example, just select Start.

To execute a javascript function for the "Next" button, you have to find the control inside that wizard and then  handle the proper event to call that method.

First, right click on the wizard control, in design mode and select "Convert to start nagivation template". Now if you look into the HTML code you will find that visual studio 2005 dynamically added the below

<StartNavigationTemplate>

<asp:Button ID="StartNextButton" runat="server" CommandName="MoveNext" Text="Next" />

</StartNavigationTemplate>


Now the Next button has an id "StartNextButton" and you can in your code behind use the below code to get this button at runtime and add the javascript code

            Button nextButton = (Button)Wizard1.FindControl("StartNavigationTemplateContainerID").FindControl("StartNextButton");
            nextButton.Attributes.Add("onclick","alert('This is the client click event');");

Hope this helps,

Comments

# re: Execute Javascript code on a navigation button in Wizard Control.

Tuesday, January 15, 2008 12:02 PM by Grace

Thanks for sharing your codes! This is exactly what I'm looking for.  And this has saved me a lot of time and headache for research!  :)

The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.