简体   繁体   中英

Using Aspx page as a partial view into a razor view

In my Asp.Net MVC3 project, I have an aspx page called as a partial view into a Razor view. In the Aspx page i have a button that has to 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 ( on the contrary the Page_Load event fire when i refresh the page). I tried several solutions but i don't resolve it.

You never connect Button2 with Button2_Click . You need to add OnClick="Button2_Click" to the button.

And you should also remove those <head> tags from around the script - partial views can't have <head> tags and runat server code doesn't need to be in them anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM