Trouble Accessing Postback Data in Custom User Control

Posted by Community Admin on 03-Aug-2018 23:13

Trouble Accessing Postback Data in Custom User Control

All Replies

Posted by Community Admin on 03-Feb-2011 00:00

Hi everyone,

I'm trying to get a highly customized hand built form into sitefinity and my problem is that the postback data isn't accessible from the code behind. My form is a user control and I'm guessing (although I'm not sure) that I should add it in the way described here:
www.sitefinity.com/.../controls-adding-a-new-control.html

After struggling for several hours, I trimmed down my form to the absolute basics and I'm still not able to access the postback data. Here's the code:

"BasicUserControl.ascx"

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BasicUserControl.ascx.cs" Inherits="SitefinityWebApp.UserControls.Assessments.BasicUserControl" %>
<div id="assessmentDiv" runat="server" clientidmode="Static">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
"BasicUserControl.ascx.cs" Code Behind
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;




Again, if I add the control via the method described at the link above, I am able to successfully create a page, drag the control onto it, run the page, step into the code behind using the debugger, yet when VS reaches the line below there is no form data being posted:
Literal1.Text = TextBox1.Text;
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.

Thanks in advance!

Ben

Posted by Community Admin on 04-Feb-2011 00:00

Bump

Posted by Community Admin on 04-Feb-2011 00:00

Never mind. I figured it out. For some reason, data isn't available at the Page_Load stage of the .net page lifecycle. If I wait until the Page_PreRender stage to retrieve the data from the form on the page, it's all there. My current prevailing theory is that Sitefinity 4.0 grabs the postback data when a form submits and hasn't finished monkeying around with it at the Page_Load stage, so you have to wait until the Page_PreRender stage before sitefinity has injected the data back into the page cycle.

This thread is closed