Answered by:
UserControls not working on custom dynamic pages.

Question
-
User-1759624489 posted
hi.
1. I created a very single user control to show error messages,
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ServerErrorMessage.ascx.cs" Inherits="UserControls_ServerErrorMessage" %>
<table bgcolor="#FFFF66" border="1" width="50%">
<tr>
<td style="text-align: center">
<asp:Label ID="lblError" runat="server"></asp:Label>
</td>
</tr>
</table>
public partial class UserControls_ServerErrorMessage : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
lblError.Text = (string)ViewState["errorMessage"];
}
private string _errorMessage;
public string ErrorMessage
{
get { return _errorMessage; }
set
{
lblError.Text = value;
_errorMessage = vale;
}
}
}2. I droped the usercontrol in a CUSTOM DYNAMIC page and added the following code.
protected void OnGridViewRowDeleted(object sender, GridViewDeletedEventArgs e)
{
if (e.Exception != null)
{
ServerErrorMessage1.ErrorMessage = e.Exception.Message;
ServerErrorMessage1.Visible = true;
}
DetailsView1.DataBind();
}The user control never shows up; i have no Idea, I am lost. I already debugged and the ErrorMessage property is set. so?'
Thursday, September 4, 2008 11:41 AM
Answers
-
User660823006 posted
Is this a question related to the new Dynamic Data feature in .NET 3.5 SP1? It doesn't appear to be, you probably should send this in the general control forum. I think your problem is that you should be setting the label text in Page_PreRender instead of Page_Load. Your setting it to early.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 4, 2008 3:30 PM
All replies
-
User660823006 posted
Is this a question related to the new Dynamic Data feature in .NET 3.5 SP1? It doesn't appear to be, you probably should send this in the general control forum. I think your problem is that you should be setting the label text in Page_PreRender instead of Page_Load. Your setting it to early.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 4, 2008 3:30 PM -
User-1759624489 posted
Is this a question related to the new Dynamic Data feature in .NET 3.5 SP1? Not exactly, but it works on other webpages, it doesnt work on dynamic web pages.
Maybe its a stupid thing but I havent been able to solve it.
I tried this>
protected void OnGridViewRowDeleted(object sender, GridViewDeletedEventArgs e)
{
if (e.Exception != null)
{
ServerErrorMessage1.Visible = true;
ServerErrorMessage1.ErrorMessage = e.Exception.Message;
}
DetailsView1.DataBind();
}<uc1:ServerErrorMessage ID="ServerErrorMessage1" runat="server" />
And nothing comes up, why_? it makes no sense!!!
Thursday, September 4, 2008 3:39 PM -
User660823006 posted
Did you try setting the label in Page_PreRender instead of Page_Load like my previous message asked?
Thursday, September 4, 2008 3:51 PM -
User-1759624489 posted
Yes. on the page pre render of the USER CONTROL.
public partial class UserControls_ServerErrorMessage : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void OnPreRender(EventArgs e)
{
lblError.Text = (string)ViewState["errorMessage"];
base.OnPreRender(e);
}
private string _errorMessage=default(string);
public string ErrorMessage
{
get { return _errorMessage; }
set
{
ViewState["errorMessage"] = value;
}
}
}
Thursday, September 4, 2008 4:00 PM