CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > visual_studio.visual_web_developer_2005_express Tags:
Item Type: NewsGroup Date Entered: 11/3/2005 5:35:35 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 3 Views: 65 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
4 Items, 1 Pages 1 |< << Go >> >|
chuckb1300
Asp.Net User
Accessing the contentplaceholder through C#11/3/2005 5:35:35 AM

0/0

Hi All,

I am attempting to access the contentplaceholder through C#.  For example, I have 2 contentplaceholders in my content page and I would like to create a label on the fly.

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="eventsschedule.aspx.cs" Inherits="eventsschedule" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"></asp:Content>
<
asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"></asp:Content>

I use to be able do somthing on the C# side as to access the PlaceHolder and add a control through C# like so.

Label mylbl = new Label();
mylbl.Text =
"asp.net is great";
Controls.Add(mylbl);
(or at least I think thats how it was done)

So if I wanted to add a new Label with some text through C# to ContentPlaceHolder2, how would I do that??

Thank you

Charles

XIII
Asp.Net User
Re: Accessing the contentplaceholder through C#11/3/2005 6:14:04 AM

0/0

Hi,

at first glance your code seems correct but you still need to state to which controls collection the label should be added. So it'll become like this:

ContentPlaceHolder2.Controls.Add(mylbl);

Grz, Kris.
Kris van der Mast [MVP] || 101 LINQ to SQL samples
chuckb1300
Asp.Net User
Re: Accessing the contentplaceholder through C#11/3/2005 2:54:00 PM

0/0

Hi,

When I attempt to do that, I get the error "The name 'ContentPlaceHolder2' does not exist in the current context"

Sad <img src=" src="/emoticons/emotion-6.gif">
chuckb1300
Asp.Net User
Re: Accessing the contentplaceholder through C#11/4/2005 6:03:57 AM

0/0

Ok, figured it out on my own.  (just wish it didnt take 3 days).
To add a label (or any other control) through c# for a specified contentplaceholder (example: ContentPlaceHolder2) do the following

//Create Label to be added to Content page (or any other control)
Label mylbl = new Label();
mylbl.Text =
"My Name is Chuck";

//Create ContentPlaceHolder
ContentPlaceHolder mpContentPlaceHolder;

//Set ContentPlaceHolder = to specific ContentPlaceHolder on your .aspx page
mpContentPlaceHolder =(ContentPlaceHolder)Master.FindControl("ContentPlaceHolder2");

if (mpContentPlaceHolder != null)
{
      
//Add C# Label to specified ContentPlaceHolder
      
mpContentPlaceHolder.Controls.Add(mylbl);
}

Thanx all,

Chuck

4 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Professional ASP.NET 2.0 Databases Authors: Thiru Thangarathinam, Pages: 504, Published: 2007
Professional C# 2008 Authors: Christian Nagel, Bill Evjen, Jay Glynn, Karli Watson, Morgan Skinner, Pages: 1782, Published: 2008
Professional ASP.NET 3.5: In C# and VB Authors: Bill Evjen, Scott Hanselman, Devin Rader, Pages: 1673, Published: 2008
Professional C# 2005 with .NET 3.0 Authors: Christian Nagel, Bill Evjen, Jay Glynn, Karli Watson, Morgan Skinner, Pages: 1748, Published: 2007
Pro ASP.NET 2.0 E-commerce in C# 2005 Authors: Paul Sarknas, Pages: 617, Published: 2006
ASP.NET 2.0 Cookbook Authors: Michael A. Kittel, Geoffrey T. Leblond, Pages: 989, Published: 2005
Pro ASP.NET 2.0 in C# 2005 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1255, Published: 2005
Pro ASP.NET 2.0 in C# 2005: Create Next-generation Web Applications with the Latest Version of Microsoft's Revolutionary Technology Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1426, Published: 2006
Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages Authors: Jacob J. Sanford, Pages: 474, Published: 2007
Pro ASP.NET 3.5 in C# 2008 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1498, Published: 2007

Web:
Accessing the contentplaceholder through C# - ASP.NET Forums I am attempting to access the contentplaceholder through C#. For example, I have 2 contentplaceholders in my content page and I would like ...
How to clear TextBoxes in a ContentPlaceHolder (using MAsterPages ... If you want to access from the same page, then you can simply use: .... foreach (Control c in ctl.Controls) { if (c is TextBox) ...
Working with ASP.NET Master Pages Programmatically You can access the contents of the master page's ContentPlaceHolder controls by using the FindControl ... C#. using System; using System.Data; using System. ...
Creating a Layout Using Master Pages A ContentPlaceHolder defines a region of the master page rendering that can be substituted ... C# Accessing Master Pages in Code Run Sample · View Source ...
ASP.NET accessing controls inside contentplaceholder .NET, ASP.NET, C#, VB.NET, SQL Server, WPF, XAML ... accessing controls inside contentplaceholder - abdul raheem 28-Feb-07 01:59 1:59:06 AM ...
K. Scott Allen : The ContentPlaceHolder – Not Just For Content <%@ Master Language="C#" %> ... Untitled Page</ title> </head> ... <form id="form1" runat="server"> <asp:ContentPlaceHolder ...<br /><a href="http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Studio_.NET_2005/Q_23066267.html" title="displaying scroll bar in contentplaceholder in master page asp.net ..." target="_" ><b>displaying scroll bar in contentplaceholder in master page asp.net ...</b></a> Sep 12, 2008 ... In vs2005 i am using contentplaceholder to display long list of ... LDAP; Miscellaneous; MS Access; MS SQL Server; MUMPS; MySQL Server; OLAP ...<br /><a href="http://authors.aspalliance.com/aspxtreme/webforms/workingwithmasterpagesprogrammatically.aspx" title="Working with Master Pages Programmatically" target="_" ><b>Working with Master Pages Programmatically</b></a> Text = "Master page label = " + mpLabel.Text End If. C#, VB. You can access the contents of the master page's ContentPlaceHolder controls by using the ...<br /><a href="http://www.15seconds.com/issue/050728.htm" title="15 Seconds : N-Tier Web Applications using ASP.NET 2.0 and SQL ..." target="_" ><b>15 Seconds : N-Tier Web Applications using ASP.NET 2.0 and SQL ...</b></a> Inside the body table, there is an asp:contentplaceholder control, which will be ... the appropriate data from the database through the data access layer. ...<br /><a href="http://www.dotnetspider.com/forum/157413-Master-page-events.aspx" title="Master page events" target="_" ><b>Master page events</b></a> Accessing members that are defined on the master page, which can consist of .... </asp:contentplaceholder> </div> </form> </body> </html> C# ...<br /></div></td> <td valign="bottom"> <script type="text/javascript"> lqm_channel = 1; lqm_publisher = 303; lqm_zone = 1; lqm_format = 6; </script> <script type="text/javascript" src="http://a.lakequincy.com/s.js"></script> </td></tr></table> <br /> <table width="100%"> <tr> <td style="width: 50%"> </td> <td> </td> </tr> </table> <br /> <div style="text-align:center"> <br /> <br /> <b>Search This Site: </b> <input type="hidden" name="cx" value="001993386287184627138:djlrq6ok3yq" /> <input type="hidden" name="cof" value="FORID:10" /> <input type="text" name="q2" id="q2" size="25" onkeypress="if(event.keyCode == 13){SearchSite('q2');return false;}" value="" /> <input type="button" name="sa" value="Search" class="Button" onclick="SearchSite('q2');" /> </div> <br /> <script type="text/javascript"> function doSubscribe(S, E){ DoSubscribe(643920, S,E); } function doFavorite(S, E){ DoFavorite(643920, S,E); } </script> </td> <td id="rightPanel" valign="top" style="width: 100px; text-align: right;"> <div style="text-align: left; font-weight: bold; margin-left: 15px"><br /> <img src="http://www.codeverge.net/images/icons/envelope2.gif" /> <a rel="nofollow" onclick="OpenInviteWin();">Invite</a><br /> <img src="http://www.codeverge.net/images/icons/folders.gif" /> <a href="../History/history_items.aspx" id="ctl00_CPH_RightMenu_A2" rel="nofollow">History</a> <br /> <img src="http://www.codeverge.net/images/icons/books.gif" /> <a href="../resources/computers" id="ctl00_CPH_RightMenu_A1">Resources</a><br /> <img src="http://www.codeverge.net/images/icons/statements.gif" /> <a href="../sitemap/SiteMap.aspx" id="ctl00_CPH_RightMenu_A5" rel="nofollow">SiteMap</a> </div> <br /> <br /> <script type="text/javascript"> lqm_channel = 1; lqm_publisher = 303; lqm_zone = 1; lqm_format = 3; </script> <script type="text/javascript" src="http://a.lakequincy.com/s.js"></script> <br /><br /> <script type="text/javascript"> lqm_channel = 1; lqm_publisher = 303; lqm_zone = 1; lqm_format = 3; </script> <script type="text/javascript" src="http://a.lakequincy.com/s.js"></script> <br /><br /> <script type="text/javascript"> lqm_channel = 1; lqm_publisher = 303; lqm_zone = 1; lqm_format = 3; </script> <script type="text/javascript" src="http://a.lakequincy.com/s.js"></script> <br /><br /> <script type="text/javascript"> lqm_channel = 1; lqm_publisher = 303; lqm_zone = 1; lqm_format = 3; </script> <script type="text/javascript" src="http://a.lakequincy.com/s.js"></script> <div style="width: 100px; overflow: hidden; text-align: left; padding: 5px; font-family: Arial;"> <br /> <a href="http://www.codeverge.net/ng.asp-net-forum.master_pages_themes_and_navigation_controls/masterpage-and-abstract-class" title="masterpage and abstract class" ><b>masterpage and abstract class</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.security/redirecting-a-user-once-signed-in" title="redirecting a user once signed in...." ><b>redirecting a user once signed in....</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.visual_studio_2005/resource-issue" title="resource issue" ><b>resource issue</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/manual-retrieving-of-data-and-displaying-it-in-reportviewer" title="manual retrieving of data and displaying it in reportviewer" ><b>manual retrieving of data and displaying it in reportviewer</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.dotnetnuke-custom_modules/custom-modules-in-their-own-assemblies" title="custom modules in their own assemblies?" ><b>custom modules in their own assemblies?</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.master_pages_themes_and_navigation_controls/one-contentplaceholder-shifting-to-the-right-when-another-displays-an-ascx-file" title="one contentplaceholder shifting to the right when another displays an ascx file" ><b>one contentplaceholder shifting to the right when another displays an ascx file</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/asp.net-1.1-users-oriented-tutorial" title="asp.net 1.1 users oriented tutorial" ><b>asp.net 1.1 users oriented tutorial</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.dotnetnuke/can-anyone-recommend-a-good-image-graphics-library" title="can anyone recommend a good image/graphics library?" ><b>can anyone recommend a good image/graphics library?</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.dotnetnuke/an-unhandled-error-has-occurred-3.1.1" title="an unhandled error has occurred. 3.1.1" ><b>an unhandled error has occurred. 3.1.1</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/a-question-about-asp.net" title="a question about asp.net" ><b>a question about asp.net</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.dotnetnuke/dnn-downloads-not-working-with-http-compression-blowery" title="dnn downloads not working with http compression (blowery)" ><b>dnn downloads not working with http compression (blowery)</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/calling-a-function-when-a-user-clicks-a-hyperlnik" title="calling a function when a user clicks a hyperlnik" ><b>calling a function when a user clicks a hyperlnik</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/asp.net-application-boundaries" title="asp.net application boundaries... ?" ><b>asp.net application boundaries... ?</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/asp.net-project-not-opening" title="asp.net project not opening" ><b>asp.net project not opening</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.dotnetnuke/stopping-url-rewrite" title="stopping url rewrite?" ><b>stopping url rewrite?</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/passing-a-value-from-html-to-aspx" title="passing a value from html to aspx" ><b>passing a value from html to aspx</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/search-string,2" title="search string" ><b>search string</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/no-javascript-please" title="no javascript please" ><b>no javascript please</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.security/session-expiring-too-quickly" title="session expiring too quickly" ><b>session expiring too quickly</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.visual_studio_2005/amateur-question" title="amateur question" ><b>amateur question</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.dotnetnuke/pixelcontainers-now-at-snowcovered-you-asked-us-for-it-now-you-can-add-pixeldesigns-to-your-own-portals" title="pixelcontainers now at snowcovered : you asked us for it now you can add pixeldesigns to your own portals" ><b>pixelcontainers now at snowcovered : you asked us for it now you can add pixeldesigns to your own portals</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.dotnetnuke/i-need-a-solution-developed" title="i need a solution developed" ><b>i need a solution developed</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.migrating_from_asp-net_1-x_to_asp-net_2-0/problems-with-web-controls-after-upgrading-web-app-from-vs-2003-to-vs-2005" title="problems with web controls after upgrading web app from vs 2003 to vs 2005" ><b>problems with web controls after upgrading web app from vs 2003 to vs 2005</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.visual_studio_2005/how-to-uninstall-visual-studio-2005-web-application-project-preview" title="how to uninstall "visual studio 2005 web application project preview"" ><b>how to uninstall "visual studio 2005 web application project preview"</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.visual_web_developer_2005_express/problem-with-leaning-videos" title="problem with leaning videos" ><b>problem with leaning videos</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.security/how-to-we-check-if-page-is-secure" title="how to we check if page is secure?" ><b>how to we check if page is secure?</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/how-to-build-asp.net-web-application-with-oop" title="how to build asp.net web application with oop?" ><b>how to build asp.net web application with oop?</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.security/login-lost-after-short-time" title="login lost after short time" ><b>login lost after short time</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.getting_started/why-hotmail" title="why hotmail" ><b>why hotmail</b></a><br/><br/><a href="http://www.codeverge.net/ng.asp-net-forum.migrating_from_asp-net_1-x_to_asp-net_2-0/in-vs2005-form-name-form1-attribute-no-longer-rendered-on-client" title="in vs2005, <form name="form1"> attribute no longer rendered on client" ><b>in vs2005, <form name="form1"> attribute no longer rendered on client</b></a><br/><br/> </div> </td> </tr> <tr> <td id="leftBottom" valign="top" style="width: 100px">   </td> <td id="ctl00_centerBottom" valign="top" align="center"> <span id="ctl00_PageFooter1_lbl"></span> <br /> All Times Are GMT </td> <td id="rightBottom" valign="top" style="width: 100px"> </td> </tr> </table> <script type="text/javascript"> //<![CDATA[ var _Rating_MemberRating = -1; var _Rating_tbl = document.getElementById('ctl00_CPH_centerFront_ctl28'); function Rating_RollRates(){ if(_Rating_tbl.rows.length < 10){ for ( i =10 ; i >0; i--){ setTimeout( function(){ var row = _Rating_tbl.insertRow(_Rating_tbl.rows.length); var cell = row.insertCell(0); cell.onclick = function(){Rating_RateIt(this.innerHTML);}; cell.innerHTML = 12 - _Rating_tbl.rows.length; cell.className = 'Rating_AvgRating'; if(cell.innerHTML == _Rating_MemberRating){ cell.title='My Rating'; cell.style.color='orange'; } }, (10-i) * 25); } setTimeout(function(){Rating_Close()},10000) } else{ Rating_Close() } } function Rating_Close(){ if(_Rating_tbl.rows.length > 1) for ( i =0 ; i < 10; i++) setTimeout(function(){ _Rating_tbl.deleteRow(_Rating_tbl.rows.length -1 )} , i * 25) } function Rating_RateIt(rating){ ItemPageWs.RateItem(643920, rating, function(A){ document.getElementById('ctl00_CPH_centerFront_ctl29').innerHTML ='('+ parseFloat(A[0]).toFixed(2) +', '+ A[1] +')'; _Rating_MemberRating = rating; Rating_RollRates(); AlertMsg('Your Rating Was Updated'); Afirm( document.getElementById('ctl00_CPH_centerFront_ctl29')); }); } RestrictHeights('tcContent');Sys.Application.initialize(); //]]> </script> </form> </body> </html> <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_001993386287184627138%3Adjlrq6ok3yq&lang=en"></script> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-3447589-1"); pageTracker._trackPageview(); </script>