1

I am integrating Asp.net User control(.ascx) in my Mvc Layout page i.e is master page and i am using razor engine.

Error:Error executing child request for handler

'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper ascx.
                  Control '1_hdfData' of type 'HiddenField' must be placed inside a form tag with runat=server.

This is my code:

_Layout.cshtml:

@Html.Partial("~/UserControls/Data.ascx")

Data.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Data.ascx.cs" Inherits="MyNameSpace.Data" %>
                 <asp:HiddenField ID="hdfData" runat="server" />
                --Rest all other asp.net server side controls---.

Data.ascx.cs:

namespace MyNameSpace.Data
                {
                     public partial class Data : ViewUserControl
                     {
                         //Page_Load events and other code
                     }
                }

Is it like if i am inheriting User Control(.ascx) from ViewUserControl so i cant use asp.net control?

Can anybody help me with this?

2
  • 1
    just need to add form tag in usercontrol Commented Nov 20, 2015 at 7:03
  • I liked the topic, it's interesting :) Commented Nov 20, 2015 at 10:07

2 Answers 2

1
 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Data.ascx.cs" Inherits="MyNameSpace.Data" %>
<form runat="server">
             <asp:HiddenField ID="hdfData" runat="server" />
            --Rest all other asp.net server side controls---.
</form>
Sign up to request clarification or add additional context in comments.

4 Comments

Yes this worked correclty but i need to render 2 user control on my layout page so then where do i put this form tag?
Give different id to all form tag and use it.
i have put form tag on 2 user control but it is giving error that:A page can have only one server-side Form tag.
Give both form tag to different id.
1

I am sharing one idea, but it's not good practice.

@Html.Partial("_ASCX_FILE")

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Register Assembly="SomeAssembly" Namespace="SomeNs" TagName="ASCX_FILE" %>

<ASCX_FILE:SomeControl runat="server" ID="fooControl" />

Possibly above solution can sort out your issue.

Suggesting again, try using pure MVC flavor. :)

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.