I have read that it is not a good idea (or just straight not possible) to put ModalPopups and DynamicPopulates in Site.master. However, if I wanted to have a link in the header/footer that opened up a popup which loaded information via a DynamicPopulate, how would that be accomplished?
I've seen comments telling people to make a web user control which I did but I get the same error I got without the extra custom user control: "Web service call failed: 500". I don't think it is an error with my webmethod:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string LoadPageToBeLoaded(string contextKey)
{
return "hello";
}
Putting the objects that call this code anywhere but the masterpage yields the results I want but short of copy-pasting the code into all of the pages at the bottom (that's what the single footer is for anyway, right?) I'm not sure how to approach this.
Thanks.
EDIT: I've found out that webmethods are not allowed in user controls, so that solves that issue. But it still seems like there should be a simple way to open a modal popup and load information into it with a dynamic populate in the header or footer of a site.
Related
I'm a PHP/Rails developer and have inherited an ASP.NET application (and its maintenance). So I have a few simple questions.
1.) What's the makeup of a typical rendered(compiled?) HTML page in ASP.NET. That is, when a request is made what happens from the initial request to the time the HTML is displayed in the browser? I'm assuming some templates are combined and finally rendered but I'd like a more in-depth answer.
2.) I've been asked to remove a link from a Login form which is an aspx page. Looking at the aspx page itself it has an inherit statement, a link to the codebehind file, and links some other resources. Where do I actually remove the link from the Login page/template at? I've so far been unable to find exactly where the link is written so that I can remove it or comment it out.
Thank you!
That is, when a request is made what happens from the initial request
to the time the HTML is displayed in the browser?
I'd start learning about the ASP.Net Page Life Cycle.
I've so far been unable to find exactly where the link is written so
that I can remove it or comment it out.
I wouldn't do anything until you have at least a decent grasp of how ASP.Net works. It would be good to run through a few tutorials. ASP.Net has a nice Get Started section.
What's the makeup of a typical rendered(compiled?)
To give you a very simple instructions (trying) to help you fast understand it:
There is a page with the aspx tags, the asp.net is running the code behind and fill this tags with data.
After the filling with data on code behind, the asp.net is "running" the full page and if you have <% %> inside the aspx page, addition code runs that exist inside that.
This is a simple example:
public partial class Dokimes_StackOverFlow_Diafora : System.Web.UI.Page
{
public string cRenderMeAlso = "test";
protected void Page_Load(object sender, EventArgs e)
{
txtText.Text = "One Test";
}
}
<form id="form1" runat="server">
This will fill when the page is prepared
<asp:Literal runat="server" ID="txtText"></asp:Literal>
<br />
This will be render as the page reads out to send it to the browser
as php do
<%=cRenderMeAlso%>
</form>
Now in the place of the Literal control, you can have a full custom render control, that maybe a new complex part of a page with his elements and render.
Each page, master page, user control have a cycle of calls to help first pass all from Init() and prepare them, then pass all from Load(), and the other stage, giving the ability to initialize them in parallel - together.
Now, on PostBack the page have been keep some information's on ViewState that are posted together with the rest post data, and the Code behind use all that data to fill the controls. Also its fires on code behind any click event you have initialize on buttons and you can run some code there to do your work.
I've been asked to remove a link from a Login form
if you can not find that link is maybe on the standard login form that asp.net gives, the solution to that is to render the full template of the form, and remove it from there - but because there is the case to break the Login form, is better to not remove it and just hide it - because if you remove it and the code behind ask for it, it will throw an error - I mean for the standard asp.net forms login code that is part of the asp.net.
So if this is the case, render the login control as template (from design mode, do that on properties), see the link you search and ether make on code behind Link.Visible = false, ether remove it and delete on code behind all the reference on it.
I'm trying to build a modalpopupextender, along with a panel and content, and need to make it application-wide. I am thinking about creating it on the Masterpage, so it's accessible on all pages, but I need the content inside the panel (anything that I may need to add there) to be visible and editable from outsite the masterpage.
For now, I'm working on this, but haven't figured out how to make it accessible to other pages and classes, and so would like to have some help on it.
Basically, what I want is to work more on the idea in a near future in order to make something consistent to be used on any web application, and to be fully customizable. What I'm having trouble is with "basics", like making it accessible to the application, allow customization of some controls inside the panel from both server and client sides, and will improve everything from there.
I have tried creating a user control for it, but didn't seem to work. I'm not an expert on asp.net (few years of experience), and even less on ajax, so any help is appreciated.
Please let me know if anybody have any questions.
EDIT:
I have now succeeded somehow creating the moodal within a user control and it's almost done.
At this moment, there are 2 issues I couldn't fix:
The damn flickering that happens on Firefox 3.5 (Corporate version, can't touch this). Ocasionally during page load (Somewhere near Page_Init or Page_PreInit events, not sure), the modals I have blink quickly on the screen, only when a postback happens. I have already done some workaround, like setting style display:none, but the issue remains. Need some help on the matter.
I need to have a modal that have 2 behaviors, like windows popups. One is information, likee only showing the message with some buttons, and the other is question. For questions, I'll need to use the ConfirmButtonExtender, and so would need to tell this confirm extender and the modal that an external button (Means a button that isn't within the user control, and by that means it's outside the same UpdatePanel as the confirm extender and modal extender) will be their TargetControlID. For now, I couldn't solve this, so I thought about creating a button inside the UC and UpdatePanel that will always be the TargetControlID. When the popup is informational, it will work as a dummy hidden button (information messages are called on server-side through methods), and when it's a question, it will receive the response. The method to be executed by the button will be set through a delegate, and therefore any method may be run when it's clicked and the Yes button on the modal is pressed (It's not ready yet, and I'm not sure it will work, or even if it's a good idea).
Any thoughts on this second option is appreciated.
It's easy for elements on the masterpage to be visible and editable from outsite the masterpage.
In this example the masterpage has a label that you want to read/write from other pages
<asp:Label ID="lblSubTitle" runat="server" Text="sub title"></asp:Label>
In the codefile for the masterpage, create a property for the subtitle:
public partial class MainMasterPage : System.Web.UI.MasterPage
{
public string SubTitle
{
get
{
return lblSubTitle.Text;
}
set
{
lblSubTitle.Text = value;
}
}
}
Then any page that uses this masterpage as its MasterPageFile can find the subtitle property and read or write it.
// get a reference to the masterpage
MainMasterPage master = (MainMasterPage)Master;
//set it to the value you want.
master.SubTitle = "Custom sub title";
I have solved the issue and created a user control containing the modalpopup for showing customized messages.
Many aspects are public, so it allows high customization, and the modal and it's customized buttons work like a charm. I still have a problem regarding the flickering, but it's for another question.
Short:Is there a way to have a route-definition that will pass the "CONTROLLER/ACTION" string value to a JavaScript function in stead of actually going straight for the controller action?
More:I have a masterpage which contains the navigation of the site. Now, all the pages need this navigation wrapped around it at all times, but because I didn't want the navigation to constantly load with each pagecall, I changed all my pages to partialviews.
These partial views are loaded via the JQuery.Load() method whenever a menu item is clicked in the navigation.
This all worked very good, up till now because I noticed it's also a requirement of the website to be able to link directly to page X, rather then default.aspx.
So, as an example:The main page is my "default.aspx" page, this utilizes my master page with the navigation around it. And each call to a new page uses a javascript function that loads that particular partial view inside a div that is known in my masterpage. So, the url never changes away from "default.aspx", but my content changes seemlesly.
The problem is, those url's also need to be available when typed directly into the address bar. But, they're partial views, so loading them directly from the address bar makes them display without any masterpages around them. Therefore my question if it might be possible to capture the route typed into the address bar and pass that on to my JavaScript function that will load that route in the content div.
(I hope I explained it ok enough, if not, feel free to ask more information)
You are 100% correct to not want to hard code your URLs in your javascript code as it demolishes one of the primary tenants of MVC to do so. I'm one of those "separation of concerns" guys who will not write a single line of javascript outside of a dedicated .js file so I cannot dynamically specify the URL the way tuanvt has. What I do is use MVCs Url.Action method to emit my service URLs into hidden inputs on the master page (or the specific page if it is not used in multiple places). Then my script file simply pulls the value out of that hidden input and uses it just fine.
ASP.NET MVC View Source
<input id="serviceUrl" type="hidden" value="<%= Url.Action("Action", "Controller") %>" />
JS Source
$.getJSON($("#serviceUrl").val(), function(data) {
//write your JS success code here to parse the data
});
First challenge, as you are using AJAX to load the partial pages you need client accessible URLs for the javascript to call. Second challenge, you need URLs that will load the HomeController and pass the 'page' portion of the URL into the javascript.
For the first aspect I'd create some abstracted routes, i.e. "/ajaxaccess/{controller}/{action}/{id}" for the partial pages. That would be the first registered route. A second route would accept any controller/action reference and always get processed by the HomeController Index action.
In the /Home/Index action you grab the requested URL and slice it up, take the /{controller}/{action}/... section and pass that into your default.aspx using TempData. In your page check for the existence of the TempData and if it exists use the value therein to trigger your AJAX page load for the partial page (don't forget that you'll need to prepend '/ajaxaccess' (or whatever you choose) to the URL before it's passed to your page.
I'm not going to provide code here as I think the information you'll gain from working through this yourself will be invaluable to you moving forward.
You could use hash anchor (#) on your url and read it with javascript.
var url = document.location.toString();
if (url.match('#')) {
anchor = url.split('#');
// do whatever with anchor[1] ..
}
You can do something like this, put this in your javascript code on the view:
var szUrl=<%= ViewContext.RouteData.Route.ToString()%>;
Then the current route will be stored on the variable szUrl.
Please read this carefully in its entirety and think about it before replying. It might be a simple fix but I highly doubt it. You have to understand the scenario here and conflicts I'm explaining fully to be able to help me.
So I have copied over our web site code to a WAP project. I got rid of any reference errors. Believe me I've checked every single error. Now here comes my problem and hypothesis (it can't be solved):
We have a master page which has a bunch of public properties in it.
Almost all our .aspx.cs code is referencing some sort of property from Master and using it.
However, on the flip side, our master page cannot recognize any of my user or custom control tags that I've registered in the Master page. The register tags are fine. These were all referencing just fine together in a Web Site Project (both the master page was referencing its references to some user and custom controls and any .aspx.cs was referencing any master page public properties jsut fine).
So, if you think about this, this could be an endless loop that can never get resolved in this WAP conversion. Why? Because the way I see it, if my Master page can't reference the few user controls or custom controls in it, my master page will not compile. If the reason that my master page cannot compile and reference these user and custom controls is because there are "other errors" and those other errors being that .aspx.cs files error out because they get errors referncing the master page public properties then we have a real problem. It's like both are erroring out because both relate to each other and have problems that cannot get resolve because they're related! Do you catch my drift?
Let me give an example / analogy to put this into perspective.
MyMasterPage.aspx
(example code in it)
<%# Register Src="~/WebControls/User/Navbar.ascx" TagName="Navbar" TagPrefix="ac" %>
<%# Register TagPrefix="am" Namespace="[ourglobalnamespace].Controls.Custom" %>
<tr>
<td valign=top runat="server" id="tdNavBar"><ac:Navbar runat="server" id="navbar"></ac:Navbar></td> (this references a user control and is blowing up)
</tr>
...
<tr>
<td><am:NavigationPath runat="server" id="navPath" Seperator="ยป" /></td> (this references a custom control and is blowing up)
</tr>
Right now I get errors saying it doesn't recognize either of the controls above for whatever reason I cannot understand
MyMasterPage.aspx.cs
public BL.Store Store
{
get { return this.store; }
}
public BL.Product Product
{
get { return this.product; }
}
just showing some public properties we're exposing through the Master Page's code behind. These properties are referenced and used in .aspx.cs code behind classes throughout our code.
Example .aspx .cs using the Master Page Properties:
protected override void OnInit(EventArgs e)
{
int productID = Master.ProductID;
product = Master.Product;
protected override void OnInit(EventArgs e)
{
int productID = Master.ProductID;
product = Master.Product;
...
So imagine I now have 1500+ errors mainly due to 2 reasons and they are not becuase of reference errors (I fixed all that):
1) Master Page cannot compile
2) Code-behind for .aspx pages blow up because Master page cannot compile therefore any references to Master Page properties cause the code behind to blow up
how the hell would I be able to resolve this if both errors practically rely on each other to be fixed? It's impossible!
3) Designer files cannot be generated for those remaining files that have these problems. So I am not able to right click the Master Page and those user controls in order to convert to web application so that it will successfully create the .designer.cs files for them
so we really have 3 problems (3rd being an after effect fo 1&2) that I have no idea how to resolve here all stemming from the Master page blowing up but could be blowing up because the code-behind pages are blowing up that reference the properties of the master page that is also blowing up! Do you catch my drift?
I hope it's something stupid simple that I've overlooked but I've spent a couple days on this and I see nothing else that will allow me to resolve this mess.
Someone shoot me to get rid of this conversion pain. If anyone can help me resolve this I swear I will send you a fing case of Beer!
In my experience, most of the pain from converting a web site to a WAP is due to namespace mismatches. Check that your master page and pages that use it are in the same namespace. And verify that the ,aspx files reference the correct namespace for the code behind files in the Inherits attribute.
Perhaps consider this to help troubleshoot.
Create a new test project.
Copy your Master page into that.
Solve any reference problems there.
Get a successful build with just the Master
Add Existing Item for your webcontrols.
Add Existing Item for one of your content pages.
In my experience, there's normally a "true" error buried somewhere within the pile. They cn be quite hard to find though!
If you really think you've got circular build problems, try excluding items from the project until you get something that will build, then slowly add them back in. You may have to comment out methods or method bodies if you've got a circular reference between some classes.
Edit to add:
Circular references aren't allowed between projects, but within a project you can have them (sounds like that's what you've got). They're fairly common, and the build process can normally cope.
You also claim to have 1500 errors - I thought that Visual Studio stops counting at about 200? Wherever the limit is, you've probably hit it. Perhaps your "true" error is not showing up in the Error List.
I have several aspx pages that can be opened either normally (full screen in browser), or called from another page as a popup (I am using Greybox, fwiw)
If the page is opened as a popup in Greybox, I would like to NOT display the master page content (which displays common top and left menus, etc).
As far as I know, there is no way of knowing server side if the page is a popup, this must be detected in client side javascript (in the case of Greybox, by checking window.parent.parent), and therefore the master page content must be hidden via javascript as well.
Any ideas on how to approach this?
Create a simplified master page for the popup. Override the OnPreInit method (of the actual page) and switch out the masterpage based on a querystring argument:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
if(Request["PopUp"] == "Y")
{
MasterPageFile = "~/MyPopUp.master";
}
}
Well you could conditionally render the navigation controls etc. based on a querystring, pass the string in when it's a popup and if it exists don't render the controls. There are a few different ways to do it, but I think you should have the server not render the controls rather than client side hiding them.
P.S. Haven't heard of Greybox so I can't offer any specific insight there.
I agree. This is a server-side problem, not something to scrape into shape on the client side. It may also be valuable to organize your web pages where the common content between the pop-up and a main page is maintained separately and imported server-side into the page that has the master-page surround. Pages that link pop-ups should use the comment content, not the surrounder.
Lots of ways to do this (but I don't suppose anyone wants to know how FrontPage extensions help). Try server-side includes.