Using an Aspx page as a partial razor view

In my Asp.Net MVC3 project, I have an aspx page called Partial Razor View. On the Aspx page, I have a button that should fire an event implemented in the script part. Here is the code:

<%@ Page Language="C#" AutoEventWireup="true"  %>

<script runat="server" language="CS">

    public void Page_Load(object sender, EventArgs e)


    public void Button2_Click(object sender, EventArgs e)

<form id="frep" runat="server">

    <asp:Button ID="Button2" runat="server" Text="Button" ></asp:Button>



Now, my problem is that the button event does not fire when I click the button (opposite when the Page_Load event fires when I refresh the page). I have tried several solutions but I am not resolving this.


source to share

1 answer

You never associate Button2

with Button2_Click

. You need to add OnClick="Button2_Click"

to the button.

And you should also remove the tags <head>

from the script - partial views cannot have tags <head>

, and the runat server code should not be in them anyway.



All Articles