<asp:label id="someLabel" runat="server">Hello</asp:label
Hello is displayed when Refresh is hit in IE, but not the first time. The first time I get what I write out at code level. Does anyone have a clue what I could be doing wrong? Also, when I am in the HTML browser, and I type < I dont see the asp:xxxx controls in the intellisense.
Thanks
MBTry
<asp:label id="someLabel" runat="server" Text="Hello"></asp:label
As for the intellisense, could be a bad install
Can you post the code? I suspect that it has something to do with page.ispostback if you have something like:
if not page.ispostback then
'write the label
else
'clear the label
end if
If so, then the label will only be filled the first time the page is hit.
Hope this helps.
MajorCats
OK the ASPX page looks like this:
<%@. Page language="c#" Codebehind="DetailPage.aspx.cs" AutoEventWireup="false" Inherits="Orders.DetailPage" %>
<table width="100%" cellpadding="0">
<tr>
<td>
<center>
<p class="Title"><asp:Label id="TitleLabel" runat="server" /></p>
</center>
</td>
</tr>
</table>
And the code looks like:
public class DetailPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label TitleLabel;private void Page_Load(object sender, System.EventArgs e)
{
TitleLabel.Text = "Hello World";
}#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);}
#endregion
}
I should elaborate a little more, because I seem to have pinned down the "general" area of the problem.
public class DetailPage : System.Web.UI.Page, IDetailView
{
protected System.Web.UI.WebControls.Label TitleLabel;private void Page_Load(object sender, System.EventArgs e)
{
Controller.SetDate(Context.Request["date"]);
}#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);}
#endregionpublic void SetDetailTitle(string title)
{
TitleLabel.Text = title;
}protected DetailController Controller
{
get
{
_controller = (DetailController)Session["DetailController"];
if( _controller == null)
{
_controller = new DetailController(this, (DetailProvider)Session["DetailProvider"]);
Session["DetailController"] = _controller;
}return _controller;
}}
}
When the page loads, the Controller for the page is accessed. If not Controller is in the Session, a new one is created. A DetailProvider provides the necessary information for the controller to do its job. All it does is return a string to the controller. The controller takes in a view that it works with, in this case the ASPX code-behind page. The controller does something very similar to this:
public void SetDate(string date)
{
_view.SetDetailTitle(_provider.GetDetail(date).Title);
}
The above code can be changed to the following, which produces the same erroneous behaviour:
public void SetDate(string date)
{
_view.SetDetailTitle("This is a test");
}
In the above code, there is a call to some other object (accessed via the session) during Page_Load. Either the is a problem doing this, or the code to access the Session is wrong, but it affects what happens during execution. Is it possible that accessing the page via an interface in the controller is affecting it? That would be inconsistent anyway, as it works the first time. The only thing that is different, is that the second time around the Controller is retrieved from the Session. Interestingly, if I make it that the Controller property ALWAYS creates a new Controller and returns it, it all works fine. Is there something I need to do with the Session?
I'm at a loss.
I just made the following aspx and aspx.cs, and both methods work fine when I refresh:
Aspx code:
<%@. Page language="c#" Codebehind="DetailPage.aspx.cs" AutoEventWireup="false" Inherits="Orders.DetailPage" %
<table width="100%" cellpadding="0"
<tr
<td
<center
From Code: <p class="Title"><asp:Label id="TitleLabel1" runat="server" /></p
</center
<center
Between label tags: <p class="Title"><asp:Label id="TitleLabel2" runat="server">Hello World!</asp:Label></p
</center
</td
</tr
</table
And the CS code:
using System;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Orders
{
public class DetailPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label TitleLabel1;
private void Page_Load(object sender, System.EventArgs e)
{
TitleLabel1.Text = "Hello World";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
Nate,
Thanks for helping out. Did you see my message just before yours, mentioning how the Controller works? It seems if I get the obejct from the session to then get the data to update the UI, it fails. I am investigating, but it seems you are right - in my app your scenario above that works works for me too...tres irritating.
Thanks again
MB
Sussed it. The Controller takes the view in on construction and is stored in the session. Inter-request calls will involve a new page being reconstitued, while the controller is pointing to the first page that was constituted,.....
0 comments:
Post a Comment