i want to set my page title dynamically so when i run this code it is have error . please solution.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Title = DetailsView.FindControl("headline").Text.Trim();
}
}
peshangm
Member
73 Points
137 Posts
Page title dynamically
May 19, 2012 08:51 AM|LINK
Dear
i want to set my page title dynamically so when i run this code it is have error . please solution.
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { this.Title = DetailsView.FindControl("headline").Text.Trim(); } }<asp:DetailsView ID="DetailsView" runat="server" AutoGenerateRows="False" DataKeyNames="articleID" DataSourceID="AccessDataSourceDetailsView" Height="50px" BorderWidth="0px" CellPadding="0" GridLines="None"> <RowStyle CssClass="rowstyle" /> <Fields> <asp:TemplateField SortExpression="headline" ShowHeader="False"> <ItemTemplate> <h2><asp:Label ID="headline" runat="server" CssClass="LinkHed" Text='<%# Bind("headline") %>'></asp:Label></h2> <br /> <div align="left"> <!-- AddThis Button BEGIN --> <div class="addthis_toolbox addthis_default_style addthis_32x32_style"> <a class="addthis_button_preferred_1"></a> <a class="addthis_button_preferred_2"></a> <a class="addthis_button_preferred_3"></a> <a class="addthis_button_preferred_4"></a> <a class="addthis_button_compact"></a> <a class="addthis_counter addthis_bubble_style"></a> </div> <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4f887df5708fd1a0"></script> <!-- AddThis Button END --> </div> <br /> به‌شی‌ <asp:Label CssClass="LinkPri" ID="Label1" runat="server" Text='<%# Bind("catName") %>'></asp:Label> له‌به‌رواری‌ :<asp:Label CssClass="LinkPri" ID="Label2" runat="server" Text='<%# Bind("publishDate") %>'></asp:Label> <br /> <img src="App_Themes/Shewa/Images/fareza.png" style="border-top-style: 0; border-right-style: 0; border-bottom-style: 0; border-left-style: 0; border-width: 0px; border-top-color: 0; border-right-color: 0; border-bottom-color: 0; border-left-color: 0; float: right" /> <br /> <img src='<%# Eval("pic") %>' width="410" height="170" style="float: left" /> <asp:Label cssclass="LinkSum" ID="fullStory" runat="server" Text='<%# Bind("fullStory") %>'></asp:Label> <img src="App_Themes/Shewa/Images/fareza1.png" style="border-style: 0; border-color: 0; border-width: 0px; float: left" /> </ItemTemplate> </asp:TemplateField> </Fields> </asp:DetailsView> <asp:AccessDataSource ID="AccessDataSourceDetailsView" runat="server" DataFile="App_Data/ASPNetDB.mdb" SelectCommand="SELECT News_Articles.*, News_Categories.*, News_Articles.articleID AS Expr1 FROM (News_Articles INNER JOIN News_Categories ON News_Articles.catID = News_Categories.catID) WHERE (News_Articles.articleID = ?)" UpdateCommand="UPDATE News_Articles SET hit = hit + 1"> <SelectParameters> <asp:QueryStringParameter Name="articleID" QueryStringField="articalID" Type="Int32" /> </SelectParameters> </asp:AccessDataSource>Suly Web For It Solution.
sunilgurjar
Contributor
2252 Points
478 Posts
Re: Page title dynamically
May 19, 2012 08:54 AM|LINK
protected void Page_Load(object sender, EventArgs e) { //bindDetailsView here then find control headlinethis.Title = DetailsView.FindControl("headline").Text.Trim(); }read my blog
http://sunilgurjar.blogspot.com/
ramiramilu
All-Star
95305 Points
14072 Posts
Re: Page title dynamically
May 19, 2012 09:05 AM|LINK
Always check for null when you use FindControl() on any Databound control..using simple If() condition...in that case you will not have a code break..
Thanks,
JumpStart
vickyshahzad
Member
64 Points
27 Posts
Re: Page title dynamically
May 19, 2012 09:10 AM|LINK
Hi..You should first bind the details view before setting the label text in it.
first bind it then call the same code. will work for you...
peshangm
Member
73 Points
137 Posts
Re: Page title dynamically
May 19, 2012 09:04 PM|LINK
how can do it please write to me.
thanks
Suly Web For It Solution.
peshangm
Member
73 Points
137 Posts
Re: Page title dynamically
May 19, 2012 09:05 PM|LINK
i try it but it is not work
Suly Web For It Solution.
basheerkal
Star
10672 Points
2426 Posts
Re: Page title dynamically
May 20, 2012 05:58 AM|LINK
This should work
protected void Page_Load(object sender, EventArgs e) { Label lbl= (Label)(DetailsView1.FindControl("headline")); this.Title = lbl.Text; }(Talk less..Work more)
sriramabi
Contributor
4351 Points
1277 Posts
Re: Page title dynamically
May 20, 2012 07:46 AM|LINK
pls check
http://www.4guysfromrolla.com/articles/051006-1.aspx
http://www.devasp.net/net/articles/display/851.html
thank u
Mastan Oli
Contributor
5088 Points
998 Posts
Re: Page title dynamically
May 20, 2012 07:56 AM|LINK
write in the page_loadcomplete event, like
protected void Page_LoadComplete(object sender, EventArgs e) { Label headline = DetailsView.FindControl("headline") as Label; if (headline != null) this.Title = headline.Text.Trim(); }playingOOPS | மெய்ப்பொருள் காண்பதறிவு
Mark as Answer If you find helpful
peshangm
Member
73 Points
137 Posts
Re: Page title dynamically
May 20, 2012 01:42 PM|LINK
thnks
Suly Web For It Solution.