Hi,
I'm maintaining a website with alot of files, and every page uses server controls for both the header and the footer. On some of the pages I don't want to show part of the header, however I am still including the header. The only way I can think to do this is to have a seperate header for the pages I want to display different . This is a major pain if I have to do it this way. Is there anyway I can pass a variable to the header server control ? I'd love to pass an "on" or "off" and display the part of the header accordingly. This is what my relevant parts of my page look like on every page
<%@dotnet.itags.org.RegisterTagPrefix="abc"TagName="myHeader"Src="../includes/myHeader.ascx" %>
<html>
<body>
<abc:myHeaderrunat="server"id="myHeader"/>
...........
</body>
</html>
If you have source access to your header/footer server control, then you can create a property called something like 'DisplayMode' and assign it with a default value, i.e.: ON. And inside these controls, do a check on the mode what to display.
Your server control on the page files would be look like:
<abc:myHeader runat="server" id="myHeader" DisplayMode="Off" />
hi Jack,
This sounds great. How would I go about creating the property? Could you possibly give me an example ? :)
Much appreciated,
mikeg123
Hi,
Well I think you can do it in various ways.
1. Make some public properties within your UserControl and the pages where you don't want to use certain areas make them invisible through the properties.
2. You can write some code in your Web user control in which you can check the current URL and make the portion available or not available. You can get the current url by Request.Path.ToString(); But for sure this method will be a lengthy one because you have to mention all the url's for which you want to make changes in the header.
3. You can pass a query string variable and check it on the UserControl's load event with Request.QueryString["variableName"]. I think this would be a reasonable way because for certain situations you just have to pass the value in the query string variable and you write code in the user control to handle the situation.
These are the possible ways that I can advise you there might be more.
I hope it will solve your problem
Thanks and best regards,
#2 & #3 wont work for me, however your first suggestion sounds great
I have created this property in the user control, but I'm not sure how I am supposed to access the information I am passsing ?
PublicProperty displayBanner()
Get
EndGet
Set(ByVal value)EndSet
EndProperty
thanks very much!!
Example in c#:
public class myHeader{// private fieldsprivate string _displayMode ="On";// you can work little more to create an Enum to limit types ...// public propertypublic string DisplayMode {set {if (!string.IsNullOrEmpty(value)) { _displayMode =value; } } } ...// eventsprotected void OnLoad() {if (string.Compare(_displayMode,"off",true) == 0) {// hide control }else if (string.Compare(_displayMode,"alternate",true) == 0) {// display an alternate view }else {// show up normally } }}
Hi Jack,
You wouldnt be able to give me one in VB would you? I apologize for not specifying before, I thought I would be able to convert it, but this is pretty confusing for me.
Very much appreciated, have a good day!
Thanks again,
hehe, I'm not a VB.NET developer. however, I've converted to VB.NET, let me know if it works. I think you should get the idea at least.
Public Class myHeader' private fieldsPrivate _displayModeAs String ="On"' you can work little more to create an Enum to limit types ...' public propertyPublic WriteOnly Property DisplayMode()As String Set (ByVal ValueAs String)If Not String.IsNullOrEmpty(value)Then _displayMode = valueEnd If End Set End Property ...' eventsProtected Sub OnLoad()If String.Compare(_displayMode,"off",True) = 0Then' hide controlElse If String.Compare(_displayMode,"alternate",True) = 0Then' display an alternate viewElse' show up normallyEnd If End SubEnd Class
awesome thanks so much it worked!!
this is a problem ive been pushing under the rug for literally two years, much apprecaited !
0 comments:
Post a Comment