I've built an asp website and i have the following issues:-
i'm using a master page in it and have defined two contentplaceholders one in head one in content, and i've specified the page title in the top most directive at the #page directive but the page title doesn't show up. I have to manually add a tag for it.
Secondly when i create a content page from a master page it creates it and when i rename it, it doesn't rename it's class. It remains _Default, thus every page was having an inherit to _default.
Most importantly
I'm using a page to enter and view data to the database. I've used a boolean called isadmin which i set according to credentials at page load. and i'm added a panel where it's visible property is set to Visible = '<%#IsAdmin %>'. It works properly when i run it through the visual studio environment but when i publish it and run it doesn't work and the panel just comes and stays there. Why is it happening? Any idea?
Thanks
The Visible problem is fixed as i had to enable windows authentication on the server. Awaiting answers for the other two issues. Thanks
Try to add a <head runat=server> to the master page. Only then ASP.net can "see" the tag and modify it
It is not that bad that several aspx-pages have identical class names. ASP.NET 2.0 started to process every page as its own compiling unit or so. Pages cannot see each other. There is a special directive to make pages see each other and instanciate or manipulate them. So it should not do much harm
Maybe you did not test this correctly and are mistaken that it DOES work in Visual Studio??? But in any case I would suggest that you move your logic into OnInit, then it runs much earlier. I think the control tree is build before Page.OnLoad. What you do is data binding, that might run only if DataBind is called, I'm not sure
Or use the safe way: Make IsAdmin a property so that it initializes itself on first call and caches the result in a variable
Regarding question #2 - add your content pages via Project -> Add New Item, and name it appropriately there. That way the naming is consistent and correct throughout.
Regarding #3, what HTML is output when you run it from the server?
your first issue can be solved by filling out the title part of the #Page directive in your .aspx pages. The master page will display that text in the browsers title bar.
and prob #2 should be solved by adding the files using the file add option in visual studio.
Related
Yes, the famous "'Sys' is undefined" Microsoft JS issue.
I've already done about 4 hours of digging and trying every suggestion I can find about it, so before you immediately call this a duplicate, here me out please.
Ultimately, this question is exactly the same as this one, but the accepted answer isn't relevant to my situation, and the OP is no longer an active member.
Background
There are about a hundred pages in this application. Each of them ultimately inherits from the same base class. This base class overrides the Init method and dynamically adds a ScriptManager to it as the first Form control.
On one single page out of them all, I encounter the issue described in the post I linked. I mentioned that the accepted answer was relevant. Here's why:
I'm not making any Sys. calls
My page doesn't have any AJAX-enabled controls on it
My page doesn't have any JavaScript on it
My web.config is accurate, it includes the proper handler entries
The issue is reproducible on both IIS 6.0 and IIS 7+
If I explicitly add a ScriptManager to the page via <asp:ScriptManager />, the ScriptResource.axd include still doesn't render to the output page
I've tried clearing browser history, Temporary ASP.NET Files, rebooting, etc. with no change in behavior
An older version of the application in our UAT environment functions correctly; the base page code nor the web.config file have changed since then
I'm completely stumped. It's an ASP.NET 3.5 web site project running on Win Server 2003 with IIS 6.0 (both Prod and UAT). My developer environment is Win7 with IIS 7.5. Same behavior in both environments.
Question
Does anybody have any ideas? I'm starting to think it's a bug in the ASP.NET 3.5.1 framework...
I've just had a similar issue that I seem to have just resolved.
IF you are overriding any other page lifecyle events on your page other than PageLoad make sure to trigger the base version of the event. E.g. I was using OnPreRenderComplete
protected override void OnPreRenderComplete(EventArgs e)
{
base.OnPreRenderComplete(e); //ADDING THIS LINE FIXED THE PROBLEM
//Add THEAD etc to Gridview
if (gvQueue.Rows.Count > 0)
{
gvQueue.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
Since you have tried everything else, and because it is reproducible, I can think of 3 possible causes that you can check:
1) The element not being defined correctly.
Make sure that the head element has runat="server" specified. We always provide an id as well, although I don't think that is strictly required:
<head id="HEAD1" runat="server">
2) The code that is causing the exception is being executed prior to the inclusion of the ScriptResource.axd.
To verify whether this is the case or not, I look at what has loaded in the page so far when the exception occurs. If I don't see the resource that is being reported as missing, I know I have an ordering problem.
I have seen this caused by two hooks of Page.Init (or other methods) in the inheritance tree and when this occurs, you cannot guarantee an order of execution.
3) An invalid page structure.
I have seen numerous cases where a misplaced, easily overlooked character, such as a single quote, double quote or < silently wrecks the page or javascript structure.
To verify that this is not the case, I first validate the page in design mode (Edit, Advanced, Validate Document) and correct any errors.
If there are no errors in design mode, I validate the rendered page by copying the source of the rendered page into an empty page within the project and then validating. This process has caught more than one subtle issue in the page structure.
4) If none of the above solve the problem, there could be an issue with the framework. If there is, it could possibly be caused by element names or order in your page. You can try removing or reordering items in your page until the problem goes away.
Hope this helps.
I have a web solution with Visual Studio 2010 and ASP.Net 4.0. In this solution there is a web site as well as a class library.
I added a new User Control to the site and was able to build everything. I was even able to publish with the new control. The issue arises when I try to reference the class name of that control in a different part of code. When I do this, I still am able to build / rebuild the entire solution. But when I try to publish, I get the error "type or namespace name could not be found."
When we publish, we always UNCHECK the box "Allow this precompiled site to be updatable" and we always CHECK the box "Use fixed naming and single page assemblies."
If I do a publish and UNCHECK the box "Use fixed naming and single page assemblies" it will publish just fine. But for some reason I can not get it to publish with that box CHECKED which is what I need to be able to do.
I have tried:
Cleaning the solution
Restarting Visual Studio
Restarting Computer
Clearing out .net temp files folder
Recreating the control
Putting everything in website into a namespace
Any help or insight would be greatly appreciated.
Thanks.
EDIT:
I figured it out. I was adding this new control dynamically. But I didn't realize it also needed registered on the page that I am using it on. After registering the control, everything worked as expected
When you want to use your web user control dynamically, as you use other .net controls like textbox, label etc. you need to follow these steps.
(1) Add a ClassName property in your control directive as below (in ascx file)
<%# Control Language="C#" AutoEventWireup="true" CodeFile="CustomControl.ascx.cs"
Inherits="CustomControl" ClassName="CustomControl" %>
Note : Make sure the ClassName & Inherits both are same as class name in the CS file.
(2) Add a Reference directive on the page where you want to use your web user control dynamically
<%# Reference Control="~/usercontrol/CustomControl.ascx" %>
Note : Reference directive is different then Register directive.
(3) Now you can add your user control dynamically anywhere on your page like below
ASP.CustomControl cuCtrl = (ASP.CustomControl)LoadControl("~/usercontrol/CustomControl.ascx");
//add dynamically created custom control to an existing panel or any container control on your page
pnlDemo.Controls.Add(cuCtrl);
Note : You can always include the ASP namespace in the using ;)
After this, you should not face any problem publishing even when checking the Allow this precomplied site to be updatable option.
I figured it out. I was adding this new control dynamically. But I didn't realize it also needed registered on the page that I am using it on. After registering the control, everything worked as expected.
I tried that and still have the same problem when publishing, either with reference tag or register tag it doesn't publish. Only way to work by now is to uncheck the "updatable site"
VS2005, ASP.NET, C#, IIS6
Hello friends,
I have a master page divided into three sections i.e. header, details, footer.
The header section contains web user control having AJAX tab container. We are showing or hiding tabs according to user previleges. Initially only one tab is active showing user to log in. When the user logs in other tabs are activated.
I have used <%# OutputCache Duration="120" VaryByParam="none" %> within my user control. When the user logs in NullReferenceException is generated on one of the method within that control.
When I remove the OutputCache, everything works fine.
Could someone guide me what should i do?
Thanks in advance
The "easy" way to fix this is to check if the value is null, if it is null create it.
A better way would be to find out why it is null.
One possibility is that the first time that page is called there is a parameter that determines that one of the controlls should not be created. The second time it is called it is called with a parameter that say that the controll is required, but it is using a cached version of the page that does not have that controll.
I want to find out inside a webcontrol the real type of the page that is designed in Visual Studio 2008.
I can obtain the WebFormsRootDesigner, and somehow i know it is possible to get the
file path of the aspx page.
I would like rather to get the ProjectItem for that page, because it would be an overkill to have the control parse the file, but i cannot find a way to do this.
And from the projectitem of an aspx page i have no clue how to get the page class...
I want my webcontrol to behave differently at designtime depending on the page type.
Thanks
That's a really bad design. It's always bad to have the "inner" behave differently based on the "outer", or the "child" to be based on the "parent".
Instead, have the page tell the control how to behave, by setting a property. Different pages will tell the same control to behave in different ways. This way, if you add a new page, it can still choose to use one of the existing behaviors.
I have a web site in asp.net that uses a master page. In this master page I have a multiview control with one view that has all the content for the content pages and one view that has some local content to the master page where I show error messages from all content pages.
In this error view I have a asp.net Label control that displays the error messages. Usually the label works fine, but in some few cases the label is null, which renders a NullReferenceException. Now I have handled this case by checking if the label is null before using it, but still my question is:
Why is this label null? What are the circumstances that can generate this?
EDIT: In the master page I have a method called SetErrorText that takes a string and sets the label. I'm calling this method from the content pages' Page_Load method, and this generally works fine. In all but two cases (that I've discovered so far) the label is initialised, and nothing separates these two cases from all the ones that work.
Also, all other controls in the master page are initialised, such as the View-control that houses the label.
When the Page_Load of a content page rolls around, the master page should be populated.
It seems that the problem was one of sloppiness. Someone had forgotten to delete the auto-generated Content-controls that Visual Studio throws in on all content pages where the master page has a ContentPlaceHolder-control.
If a content page has a Content-control, all controls that are placed in the ContentPlaceHolder-control on the master page will be null, it seems.
What method on the master page are you accessing the label from? Depending on the stage of the page lifecycle, the label control may not have been loaded yet
Could you be accessing it before it is created? Check the page lifecycle: http://msdn.microsoft.com/en-us/library/ms178472.aspx
I had a very similar error. In my case it was caused by .NET compiler wierdness related to the control designer file. Even if the designer file has the controls defined correctly, delete it, re-generate it and rebuild (make sure to rebuild, don't just 'build'). See the top answer here for how to do regenerate the designer file:
How do you force Visual Studio to regenerate the .designer files for aspx/ascx files?