0

I am newbie with asp.net MVC and i want something simple. I have an Index.aspx page and a UrlContent.cs class.

I am searching how to write the code of the button_click listener of the page in the class. So far havent found anything on google.

Thats all, thank you

1
  • 3
    If you want a button_click handler wired from a aspx pages to a .cs you need Webforms not MVC.... otherwise I highly recommend you to start on MVC with asp.net/mvc/overview/getting-started Commented Sep 7, 2012 at 21:42

2 Answers 2

3

MVC is a different paradigm, and doesn't really have the concept of "event listeners".

That concept was always an abstraction from how web clients/servers really communicated. To a web server, there's really only one event, and that is an HTTP request from the client. To achieve the illusion of "events", ASP.Net does some (Javascript+cookies) magic behind the scenes, and creates hidden form input tags -- containing info about which button was clicked -- within a standard HTML form, and posting the form back to the server.

MVC adheres much more closely to the native behavior of HTML/HTTP. It requires you to get accustomed to working with those technologies -- forms, GET/POST requests, and AJAX.


To handle a (submit form) button click event, you create an action in your controller that accepts parameters.

Controller

[HttpPost]
public ActionResult Index(MyModel model)
{
    // handle the submit button's "click event" here
}

View

@model MyModel

@using (@Html.BeginForm("Index", "Home")) {
    @Html.EditorForModel
    <input type='submit' value='submit' />
})
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! that's exactly what i was searching for
0

If you're running MVC, I think you're looking for something like this

@Html.ActionLink("Link Text", "Action method Name", "Controller name",new {} , new {})

Here's some documentation on more overloads.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.