I have this folder structure in my project.
Web,WebControls along with other folders. My .aspx pages are in Web folder and master page is in WebControls folder. This has caused some problems.
In anchor tags with href='#' and onclick='SomeJavascriptFunction', href value becomes /WebControls/# and this results in 404.
In anchor tags href='SomeJavascriptFunction', when user clicks on the link, it looks for /Web/SomeJavascriptFunction and this is obviously not found there.
All I want to know is what is the best practice to place Master page in the project? If I can go ahead with the present structure, how can I overcome above problems?
Thank you very much in advance.
As you're happy with the solution posted in the comments, I'm reproducing it here:
Where to leave the MasterPages:
There's no specific rules regarding that, but just leave them in the same folder you have the pages. It will make your life easier.
How to get rid of the problems posted:
I wouldn't set the href attribute with the javascript function as it is. I would rather do that: href="javascript:void()" onclick="myJavascriptFunction()".
Why my Javascript function is returning undefined:
The document ready is used to attach event handlers, not to define functions. These should stay off this block.
Related
I've been thinking about purchasing a domain and putting a website on it, but I'm not sure how I would add sub-pages. I'm probably using the wrong words, but I'll try to explain what I mean.
For example, the main page is stackoverflow.com. When you go to another page, it goes to stackoverflow.com/questions. Is this achieved using Javascript, or is it set up manually where you link an HTML file to the sub-page?
I'm not too sure where to start here, so any help is appreciated.
One of the simplest ways to set up a website with multiple pages is to create a folder for each page and an index.html file for each page. These can then be linked together using HTML anchors or JavaScript code. For detailed instructions on how to do this, I suggest checking out tutorials from W3Schools like how to make a website
Working on MVC5 asp.net website.
I have a "dashboard" page that allows the user to place pre-defined "widgets" on the page. These widgets are simply MVC 5 partial pages (Razor). I really wanted each widget to be "self-contained" so all references, scripts, etc... are within the widget's cshtml file. BUT, the main "dashboard" page also needs certain references to jQuery, bootstrap, etc...
Of course, doing this, I could encounter conflicts, duplicate references (one from main page, one from widget), etc....
Question: What is the preferred method for this scenario? Should references like jQuery and bootstrap be JUST on the main "dashboard" page? What about javascript or jQuery code that is in the widget itself? Should this remain in the widget? If so, will I encounter the issue where it doesn't have jQuery defined (because it's in the parent page), etc...?
Any thoughts on this would be appreciated?
Thanks!
**** UPDATE ****
TO further clarify: If I put the scripts, references, etc (specific to the widget) at the bottom of the widget, then when the partial page is rendered on the main page, the scripts, etc.. are not rendered at the bottom of the main page. This causes my code to act funny because of the order that things are rendered. This is one reason I ask this question. Hope this makes sense. Thanks.
Put the script code and references that are global to the application , that are used everywhere and that are not specific to a widget in the most outer page.
What i would do, is i would bundle all my script references in one place and add that bundle link to the dashboard page, this makes your code cleaner and your page will have less external references thus a better client side performance.
I'm currently building a 6 page site and have finished the template for the navigation elements, the problem is, I just put the css & js into external files for the elements that will be the same on each page but now they aren't rendering on the original page or the new page, just showing white where there should be images.
Is this because I used id's on the elements instead of classes?
I thought it wouldn't matter if the id's were on separate pages that's why I'm asking here as it could be something else.
After putting the CSS & JS into external files Dreamweaver asked if I would like to update the links, I answered yes and it changed all background images in the external css file from (images/image.jpg) to (file:///images/image.jpg), I had to change them all back to the original path. Problem solved.
It does not matter if id's are on sepereate pages. You probably have a JS error somewhere in your migration. Did you load the page with firebug/chromedevelopertools/iedevelopertools open and see if there is a JS error?
ID are not the problem. check that the relative path is still correct according to the css file. to me that seems to be the most probable mistake.
I have tried to place the slider on every page on this website: http://atripathi.com
It works on the homepage, but doesn't work on any of the other pages (About, Services, etc.)
I know it's probably an easy fix, but I can't get it at the moment.
Thank you for any help or suggestions!
Looks like the original suggestion above is correct. I'm seeing slider javascript includes at the top of your homepage that aren't on the other pages.
Generally, a good way of troubleshooting is to make copies of both pages, index-c.php and about-c.php perhaps, and start removing everything that isn't pertinent to the trouble you're having (other HTML, css includes, etc.) until you get down to only the slider on the page. Once you've done that, you might notice that the one page is slightly different than the other, making it work. You can copy back and forth until it does.
The other possibility is that there's a relative path problem somewhere, because your one page is inside a folder (though I'm guessing you have a .htaccess redirect to a root folder page)? So if all else fails, move the reduced about-c.php to the root folder and see if that then works. If so, you know it's a path problem.
Hope these suggestions help.
I see that jQuery is being included on all your pages but the cycle plugin is only included on the home page. You should be able to update your template(s) to fix this.
I am trying to set up a masterpage that contains a javascript popup subroutine that can be used in multiple web pages. The popup already works in a single page environment. I now want to migrate it to a master page. Any ideas will be greatly appreciated. I already searched this site and tried a couple of the suggestions to no avail. W small working example would help.
Thanks
Bill
Just take what you have in your single page and place it in the master page. It is really that simple. :) Then just replace the main body of the HTML in the master page with the content sections and you should be ready to go.
One thing I did discover was that for some reason the derived page had to be in the same folder as the master page.
Most likely caused by the master page referencing a subdirectory that works for the master page, but not the internal pages themselves. One workaround would be using
ScriptManager.RegisterClientScriptInclude(string Key, string URL)
like so:
ScriptManager.RegisterClientScriptInclude("uniqueIdentifier", "~/javascript/myjs.js");
Alternatively, you can embed the file as a resource and use
ScriptManager.RegisterClientScriptResource(Page, Type, Key);
like so:
ScriptManager.RegisterClientScriptResource(this.Page, typeOf(Page), "resourceKey");
this is my current favourite, seems to be most robust and flexible. Simply include the js files in your master then create an isntance on your pages
be sure to use the scriptmanager class to add the javascript