Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to render Partial Views in WebForms?

I'm touching an old WebForms project but I'm long gone from it and I'm now to used to MVC. I'm trying to refractor the project and come up with a simple issue that is making me crazy...

What would be the best way to include an .aspx file within another?

I don't want to end up having a lot of Master Files just for this, all I'm after is something like @Html.RenderPartial("MyFileName") kind'a thingy or

it's that hard to include a file in some existing files?

like image 576
balexandre Avatar asked Oct 06 '12 15:10

balexandre


1 Answers

Use UserControl Tutorial on UserControl. They are files with .ascx extension and you can include them in your pages

//UserControl1.ascx
<% @ Control Language="C#" ClassName="UserControl1" %>

 <div>
   My Custom Control: I can use any Server controls, html tags etc
 </div>

Include it in your .aspx page

<%@ Page Language="C#" %>
<%@ Register TagPrefix="uc" TagName="MyCustomControl" Src="~/Controls/UserControl1.ascx" %>
<html>
<body>
<form runat="server">
    <uc:MyCustomControl id="MyPartialView" 
        runat="server" />
</form>
</body>
like image 89
codingbiz Avatar answered Oct 01 '22 19:10

codingbiz