Background:
I have a main Masterpage that I use on all the pages of my website, certain pages in the website launch jQuery UI modal dialogs that in turn load other webforms that have their own special Modal MasterPage.
Directory Structure:
/
/templates/Main.master
/templates/Modal.master
/htmlmodals/popup.aspx
/main.aspx
The Problem:
there appear to be two problems. Firstly when I complete any action within the Modal Masterpage that causes a postback, the (popup.aspx) page attempts to try and look within the directory of the file that called the modal, so I end up with an error like
Description: HTTP 404. The resource you are looking for ...blah blah blah...
Requested URL: /popup.aspx
Another issue that I have just found, is that the generated source code form main.aspx shows that I have two form fields with exactly the same ID, even though I specified the Modal to have a different one.
<form name="aspnetForm" method="post" action="main.aspx" id="aspnetForm">
...
</form>
<div id="modal-holder">
<form name="aspnetForm" method="post" action="popup.aspx" id="aspnetForm">
...
</form>
</div>
Query:
Do I need to specify a <html><head></head><body>... etc in the Modal.master file? I ask because the pages load exactly how I want them to (including processing of code behind), with the exception of postbacks, just using the following code:
Modal.master
<%# Master Language="VB" AutoEventWireup="false" CodeBehind="modal.master.vb" Inherits="--REMOVED IDENTIFIER--.Web.Site.modal" %>
<form id="modalForm" runat="server">
<div>
<div class="alert-box" id="error-area--modal">
<p></p>
<div class="error-content"></div>
<div class="error-synopsis"></div>
<div class="validity-summary-container">
<ul></ul>
</div>
</div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<script>
initialiseEvents();
</script>
</form>
A typical modal would be launched using the following jQuery code
$('#<%= btnPopup.ClientID %>').click(function(e){
e.preventDefault();
dHeight = ($(window).height()) * 0.95;
baseDialog.dialog('option',{title:'Edit', width:'95%', height:dHeight, open:function (e, ui) {$('#modal-holder').load('/htmlmodals/popup.aspx');}}).dialog('open');
});
Update : Adding the relevant html/head/body tags to the modal master does NOT fix the postback/duplicate ID issue
Update 2 : Added an update panel around the part of the popup.aspx that posts back, doesn't appear to have worked either, still trying to do a normal postback to /popup.aspx
This SO question when-i-load-an-aspx-page-using-jquery appears to be very similar to my own question, so the answer looks like i'll have to write a javascript method to update my page instead of posting back.
Related
I have two web pages written in VisualBasic.Net:
Upload.aspx
Default.aspx
There is a link in the Default page that opens Upload page in a different window.
In the Upload window I upload a file, and I want to display the name of this file in a textbox, which in turn is in a gridview on the Default page.
I think I want an asyncronous process that won't cause the Default page to refresh, but I don't know how to do this.
I created a very simple example for you. Here is the code of the first page (your Default.aspx let's say):
<html>
<head>
<script>
function ow() {
window.open('w2.html');
}
function update(updatestr) {
document.getElementById('update').innerHTML = updatestr;
}
</script>
</head>
<body>
open window
<div id="update"></div>
</body>
</html>
This page contains a link, which opens a new window (this will be your Upload.aspx page). It also contains a simple function called update, which puts a parameter value as a div html content.
This is code of a second page (your Upload.aspx like):
<html>
<head>
<script>
function update() {
window.opener.update(document.getElementById('txt').value);
}
</script>
</head>
<body>
<input type="text" id="txt" />
<input type="button" value="Update" onclick="update()"/>
</body>
</html>
This page contains a textbox and a button. After a button click, the content of the textbox will appear in a div on the first page. You can do something similar in your case.
I've put a working demo for you.
I am using ASP.NET
I have created a user control that look like this:
when pressing the + : the score is raised by 0.5 and the opposite for minus.
The user control contains an update panel, and the pages itself containing the script manager.
When I put this user control in page and NOT inside repeater, this works perfect.
When I put this as part of a repeater. this not work at all.
I tried to delete all the update panels and still not working.
This is the error I'm getting
Don't know how to fix this.
This is the code of the user control:
Often, this error shows due to not post back:
If(!IsPostBack){
// your controls code here
}
Or, Check is your web page not using <form> tag more than once:
<form id="form1" runat="server">
<form id="form2" runat="server">
<!-- Your user controls -->
</form>
</form>
You have to use only one <form> tag in your page.
Or, try in your *.aspx page like:
EnableEventValidation="false"
I have one master page and several content pages , I need to put a form tag inside a master page to handle sending data from my html elements and do this for my content pages as well .but I need to understand what is the best way to structure for such this scenario and what would be the effect of form tag of master page on content pages ? is it possible to put form tag in content pages when the master page has this tag inside itself ? I appreciate if I have in detail explanation ?
The <form runat="server"> element lives in the master page by default when you add a new one to your project; all child pages are implemented using ContentPlaceHolders.
For example, the master page: -
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
You can have as many ContentPlaceHolders as you need (often only one is needed though). If you then add a "child page using master page", the page-specific content is added inside the relevant <asp:Content> element - these are added by default once you have specified the master page to use when adding a "child page using master page": -
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<!-- your markup, controls etc.. -->
</asp:Content>
Have a read of the MSDN docs for more - http://msdn.microsoft.com/en-us/library/aa581781.aspx
I'm working on making some changes to a Dot Net Nuke website with a customized skin. I found out that the header to the skins file was located in 'Default.aspx' here.
The form has some very strange behavior. I have had to disable the enter button because pressing within the form causes the webpage to go to "/HOME.aspx" however that action is never specified within the Default.aspx.
The code is as follows.
<dnn:Form id="Form" runat="server" ENCTYPE="multipart/form-data" >
<asp:Label ID="SkinError" runat="server" CssClass="NormalRed" Visible="False"></asp:Label>
<asp:PlaceHolder ID="SkinPlaceHolder" runat="server" />
<input id="ScrollTop" runat="server" name="ScrollTop" type="hidden" />
<input id="__dnnVariable" runat="server" name="__dnnVariable" type="hidden" />
</dnn:Form>
The form after being processed displays in the browser as.
<form name="Form" method="post" action="/HOME.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="Form" enctype="multipart/form-data">
What I want the code to display as is simply.
<form name="Form" method="get" action="/SearchResults.aspx" id="Form">
I tried removing the dnn code with the html directly but removing the dnn form causes the website to crash.
EDIT
What I'm trying to do can be seen at http://www.ontariosheep.org
Notice if you press the button the search works but pressing enter causes the page to refresh.
You can use some Javascript to do this:
jQuery('#SearchBox').keypress(function(e){
if(e.which == 13){
e.preventDefault();CallSearchPage('http://www.ontariosheep.org/SearchResults.aspx');
}
});
You would need to put that in script tags and also in a jQuery document ready area... like
<script>
jQuery(document).ready(function(){
//code above here
});
</script>
Changing the behavior of the form in DNN is not something you are going to do easily. DNN uses the ASP.NET Web Forms model, so the action for the page is always the current page.
If you want to customize this the only real way is to modify the form action via JavaScript on a specific page, but note that doing that prior to a button click or similar trigger WILL break all administration functions on the page that require a postback to the server.
What are you trying to accomplish?
I'm really new to ASP.NET MVC, and I'm trying to integrate some Javascript into a website I'm making as a test of this technology.
My question is this: how can I insert Javascript code into a View?
Let's say that I start out with the default ASP.NET MVC template. In terms of Views, this creates a Master page, a "Home" View, and an "About" view. The "Home" View, called Index.aspx, looks like this:
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%= Html.Encode(ViewData["Message"]) %></h2>
<p>
To learn more about ASP.NET MVC visit http://asp.net/mvc.
</p>
<p>Welcome to this testing site!</p>
</asp:Content>
Adding a <script> tag here didn't work. Where and how should I do it?
P.S.: I have a feeling I'm missing something very basic... Thanks in advance!
One thing you may want to consider is adding a "scripts" content place holder to your master page, that loads scripts at the end of the body. This way you load your scripts at the end of the page so that it doesn't slow down loading the DOM elements (once a script starts loading it only does one request at a time, because the code can affect the DOM). This gets a little tricky with PartialView -- if you include code in them you need to figure out a way to delay executing anything that relies on later scripts after those scripts have loaded. A compromise might be to load things like jQuery in the header and the rest of your common scripts at the end of the body.
Site.Master
<body>
...
<asp:ContentPlaceHolder runat="server" id="MainContent"></asp:ContentPlaceHolder>
...
<script type="text/javascript" src="<%= Url.Content( "~/scripts/jquery-1.4.1.min.js" ) %>"></script>
<asp:ContentPlaceHolder runat="server" id="ScriptContent"></asp:ContentPlaceHolder>
</body>
</html>
View
<asp:Content runat="server" ID="mainContent" ContentPlaceHolderID="MainContent">
... HTML ...
</asp:Content>
<asp:Content runat="server" ID="scriptContent" ContentPlaceHolderID="ScriptContent">
<script type="text/javascript">
$(function() {
$('.selector').click( function() {
...
});
});
</script>
</asp:Content>
Just stumbled on this question and would like add a comment that in Visual Studio 2013 it can be done in more elegant way.
In your master page just put the following code at the bottom of the page (in the default generated master page this code is already there):
<body>
...
#RenderSection("scripts", required: false)
</body>
</html>
Then in your view just at the bottom the following code:
#section scripts
{
<script src="...script url..."></script>
}
or if you use bundles
#section scripts {
#Scripts.Render("~/bundles/<script id>")
}
or you can put a <script>...</script> section with your Javascript code into the #section scripts block in the view.
Go create an additional <asp:ContentPlaceHolder> inside of the <head> of your masterpage and then your views will have a third <asp:Content> section for you to register external .js files, custom <script> blocks, external .css files, and custom <style> blocks.
The <script> tag needs to go inside an <asp:Content> block. (Otherwise, where would it end up?)