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"  %>

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

    public void Page_Load(object sender, EventArgs e)
    {
       //
        //Instructions
        //
    }  

    }

    public void Button2_Click(object sender, EventArgs e)
    {
        //
        //Instructions
        //
    }
</script>
</head>

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

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

</form>

      

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.

+3


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.

0


source







All Articles