This is a migrated thread and some comments may be shown as answers.

Button click event

4 Answers 3300 Views
Button
This is a migrated thread and some comments may be shown as answers.
Uma
Top achievements
Rank 1
Uma asked on 30 Jul 2014, 06:43 AM
Hi,

I have a view with telerik asp.net mvc button on it. When the user clicks on this button, I would like to redirect to another view. I looked into the control documentation but could not find anything in the Events section. Please help me.
Below is my button code for reference.

<div style="text-align:right">
    @(Html.Kendo().Button()
    .Name("add")
    .Content("Add Project")
    .HtmlAttributes(new { type = "button" })
    .Events(e => e.Click("GoToCreateView")))
</div>

Thanks.

4 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 30 Jul 2014, 07:32 AM
Hello Uma,


Indeed in the current case you could use the click event of the Button widget and navigate to the view in the event handler.

Let me know if I could assist further on this topic.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Cyril
Top achievements
Rank 1
answered on 21 Oct 2014, 03:18 PM
I am new to MVC/cshtml and I have the same issue. I am struggling to get the script to load a new view when the button is clicked.
Would you be able to show me an example of the script code inside the click event handler to navigate to a new view? 
0
Dimiter Madjarov
Telerik team
answered on 22 Oct 2014, 08:22 AM
Hello Cyril,


You could navigate via JavaScript in the event handler.
E.g.
function onButtonClick(){
    window.location.href = "..."; //pass the desired url for the view
}

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Hamish
Top achievements
Rank 1
Iron
answered on 02 Aug 2022, 09:12 AM | edited on 02 Aug 2022, 09:43 AM

In case anyone else fetches up here...

A server-side solution is available using .Tag() and .HtmlAttributes() to make the button a hyperlink:

  @(Html.Kendo()
            .Button()
            .Name("add")
            .Content("Add Project")
            .Tag("a")
            .HtmlAttributes(new { @href="[desired url]"})

The Html helper Url.Action might alternatively be used for the desired url:

 @(Html.Kendo()
             .Button()
             .Name("add")
             .Content("Add")
             .Tag("a")
             .HtmlAttributes(new { @href=Url.Action("[desired action]", "[desired controller]") }))

In either case, query parameters can also be incorporated (though perhaps unlikely to apply in the OP's scenario).

Yanislav
Telerik team
commented on 04 Aug 2022, 05:10 AM

Hello Hamish,

Thank you for sharing the solution you've found with the community. It might be helpful to someone who is working on a similar to your scenario.

Tags
Button
Asked by
Uma
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Cyril
Top achievements
Rank 1
Hamish
Top achievements
Rank 1
Iron
Share this question
or