Note that there are some explanatory texts on larger screens.

plurals
  1. POSiteFinity 4.0: Trouble Accessing Postback Data in Custom User Control
    text
    copied!<p>I'm trying to get a highly customized hand built form into sitefinity 4.0 and my problem is that no matter what I do I can't access the form's postback data in the code behind. My form is a user control and I've added it in the way described here: <a href="http://www.sitefinity.com/40/help/developer-manual/controls-adding-a-new-control.html" rel="nofollow">http://www.sitefinity.com/40/help/developer-manual/controls-adding-a-new-control.html</a></p> <p>After struggling for several hours, I created a basic test form and I'm still not able to access the postback data. I've also tried adding EnableViewState="true" all over the place but the form data is still empty on postback. The exact same user control runs and posts data perfectly outside of sitefinity. I also tried other methods of accessing the postback data and I discovered that Request.Form does contain the data I need. I'd still love to access my form elements in the usual way though, so I don't have to do Request.Form for every control on the page and loop that way, which seems really hokey. </p> <p>Here's the code for the basic form:</p> <p>"BasicUserControl.ascx"</p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BasicUserControl.ascx.cs" Inherits="SitefinityWebApp.UserControls.Assessments.BasicUserControl" EnableViewState="true" %&gt; &lt;div id="assessmentDiv" runat="server"&gt; &lt;asp:TextBox ID="TextBox1" runat="server" clientidmode="Static" enableviewstate="true"&gt;&lt;/asp:TextBox&gt; &lt;asp:Literal ID="Literal1" runat="server" clientidmode="Static" enableviewstate="true"&gt;&lt;/asp:Literal&gt; &lt;asp:Button ID="Button1" runat="server" Text="Button" /&gt; &lt;/div&gt; </code></pre> <p>"BasicUserControl.ascx.cs" Code Behind</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace SitefinityWebApp.UserControls.Assessments { public partial class BasicUserControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { Literal1.Text = TextBox1.Text; } } } } </code></pre> <p>Again, if I add the control via the method described at the link above, I am able to successfully create a Sitefinity 4.0 CMS page, drag the control onto it, run the page, step into the code behind using the debugger, yet when VS2010 reaches the line below there is no form data being posted:</p> <p>Literal1.Text = TextBox1.Text;</p> <p>FYI: The reason why there is no form tag in my usercontrol.ascx code above is because I get an error when running the form thru sitefinity that only one server-side form tag can exist on a .net page (sitefinity injects it's own form tag).</p> <p>Thanks in advance for your help!</p> <p>Ben </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload