FullCalendar dayClick doesn't work in my project until the user either goes back or ahead one month then back to the present month. I inherited this project and have no previous experience with calendar functions so I'm not sure where to start, except to post the markup associated with one of the calendars. I'm rather new to StackOverflow so let me know if I need to post any other details. Thanks in advance for any suggestions.
<%# Control Language="C#" AutoEventWireup="true" CodeFile="PersonalCalendar.ascx.cs" Inherits="Controls_Events_PersonalCalendar" %>
<link id="lnkCSSFiles" type="text/css" media="screen, projection" rel="stylesheet" href="~/css/fullcalendar.css" runat="server" />
<div class="rightCol">
<div class="search masked formWhole">
<label for="searchBox">
Search</label>
<asp:TextBox ID="txtSearch" CssClass="text" runat="server" />
<asp:Button ID="btnSearch" CssClass="button" Text="Search" OnClick="btnSearch_Click"
runat="server" />
</div>
</div>
<div>
<asp:ListView ID="lsvSearch" runat="server">
<LayoutTemplate>
<h3>
Search Results</h3>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<div class="eventList">
<a href="<%#((EventsWrapper)Container.DataItem).URL %>" class="eventTitle">
<%# ((EventsWrapper)Container.DataItem).Title%></a> <span class="eventDate">
<%# ((EventsWrapper)Container.DataItem).StartDate%></span> <span class="eventLocation">
in
<%# ((EventsWrapper)Container.DataItem).City%></span> <a class="more" href="<%#((EventsWrapper)Container.DataItem).URL %>">
View Event »</a>
</div>
</ItemTemplate>
</asp:ListView>
</div>
<div id="genWidget" class="calendarWidget" runat="server">
<div id="calendar">
</div>
</div>
<!--end Calendar Widget-->
<asp:Literal ID="litJavaScripts" Text="~/tft-js/core/fullcalendar.js,~/tft-js/core/jquery.dateformat.js,~/tft-js/jquery.tools.min.js" runat="server" />
<script type="text/javascript">
function outputAMPM(d) {
var date = new Date(d);
h = d.getHours();
if (h < 12)
return "AM";
return "PM";
}
$(document).ready(function () {
$("#calendar").fullCalendar({
<% if (m_Year.HasValue){ %>year: <%= m_Year.Value %>,<%} %>
<% if (m_Month.HasValue){ %>month: <%= m_Month.Value - 1 %>,<%} %>
events: '<%= ResolveClientUrl(Request.AppRelativeCurrentExecutionFilePath) + (!String.IsNullOrEmpty(Request.QueryString.ToString()) ? "?" + Request.QueryString.ToString() : "") %>',
header: {
left: 'prev,next title',
center: '',
right: ''
},
aspectRatio: 1.1,
titleLength: <%= TitleLength %>,
weekSelectURL: '<%= ResolveClientUrl("~/events.aspx") + m_DaylessQueryString + (!String.IsNullOrEmpty(m_DaylessQueryString) ? "&" : "?") %>',
weekMode: 'variable',
timeFormat: 'H(:mm)',
eventRender: function(event, element) {
element.append('<div class="eventPopup"><div class="popupWrapper"><span class="title">'+ event.title + '</span><span>' + $.format.date(event.start, "MM/dd/yyyy hh:mm") + outputAMPM(event.start) + '</span><span class="address">' + event.Address1+ '<br />' + event.Address2+ '<br />' + event.City + ', ' +event.State +' ' + event.Zip + '</span>' + '<a class="more" href="'+event.url +'">'+event.url +'</a><a class="more" href="all-events.aspx">View More</a><div class="clearfix"><div class="addthis_toolbox"><a class="addthis_button_facebook" addthis:url="'+ event.url +'" addthis:title="'+ event.title + '"></a><a class="addthis_button_tweet" tw:count="none"></a><a class="addthis_button_google_plusone" <%= "g:plusone:count=\"false\"" %>></a></div></div></div></div>');
},
eventAfterRender: function(event, element,view){
setTimeout(function(){
$('div.fc-event > a').tooltip().dynamic();
$('div.fc-event').hover(function() {
$(this).addClass('hoveredEvent');
},
function() {
$(this).removeClass('hoveredEvent');
}
);
},1000);
}
});
$(".fc-day-number").each(function(){
var num = $(this).find("a").html();
$(this).html(num);
});
});
</script>
<script type="text/javascript">
</script>
<script type="text/javascript" src="http://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5098045873d5139d"></script>
I encountered this problem when i used it. It was due to the code not written in $(document).ready(function(){}). Since you have done that try specifying a default view. to it.
If possible create a http://www.jsfiddle.net
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a button to trigger the modal popup window in aspx page. I would like to populate the window with the content from database when the button is clicked.
Like,
When the button is clicked, the backend code should get executed, populate the modal window and then show the modal window.
How this can be done?
This is what I have tried.
ASPX Page:
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication2.WebForm1" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
Sub ServerButton_Click(ByVal sender As Object, ByVal e As EventArgs)
myfunction()
ClientScript.RegisterStartupScript(Me.GetType(), "key", "launchModal();", True)
End Sub
</script>
<script type="text/javascript">
var launch = false;
function launchModal()
{
launch = true;
}
function pageLoad() {
if (launch) {
$find("mpe").show();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="ClientButton" runat="server" Text="Launch Modal Popup (Client)" />
<asp:ScriptManager ID="asm" runat="server" />
<asp:Panel ID="ModalPanel" runat="server" Width="500px">
This is my modal window<br />
<asp:Label runat="server" ID="mylbl" />
<br />
<asp:Button ID="OKButton" runat="server" Text="Close" />
</asp:Panel>
<cc1:ModalPopupExtender ID="mpe" runat="server" TargetControlId="ClientButton" PopupControlID="ModalPanel" OkControlID="OKButton" />
</div>
</form>
</body>
</html>
Code Behind:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Script.Services
<WebMethod>
Protected Sub myfunction()
mylbl.Text = "mylabel text"
End Sub
In the above code, I tried to access a method (myfunction) form the client side script which is declared with "runat=server".
Ok. I've created a solution in Monodevelop (but you can migrate it to VS without problems, only moving the folders and files). I imagine you want something like this:
The button "Show popup" is in the page, at the same level, there's a webusercontrol, this is the popup (well, really the webusercontrol is inside of divs, i put these divs to follow the structure of bootstrap's modal):
<style type="text/css">
.popup-someEntity{width: 500px;}
</style>
</asp:Content>
<asp:Content ContentPlaceHolderID="cphContent" ID="cphContentContent" runat="server">
<div class="page-header">
<h3>My POPUP:</h3>
</div>
<!-- ======== POPUP : set Visible property to false. this must be shown from codebehind depending of an event... === -->
<div class="">
<asp:LinkButton ID="btnShowPopup" runat="server" OnClick="btnShowPopup_Click"
CssClass="btn btn-primary"
Text="Show Popup"></asp:LinkButton>
</div>
<!-- Modal popup: Note that you must wrap the control with outer divs -->
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="largeModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
<uc1:WucPopup runat="server" id="WucPopup" Visible="false"/>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<!-- /Modal popup: -->
</asp:Content>
When you click the button "Show popup" then in code behind executes this:
protected void btnShowPopup_Click(object sender, EventArgs e)
{
this.WucPopup.ShowControl();
}
As you've noticed in html code, "WucPopup" is Visible=False so the ShowControl() method populates the table and change to Visible=true. Here is the code of the WucPopup's code behind:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnClose_Click(object sender, EventArgs e)
{
CloseControl();
}
public void CloseControl()
{
this.Visible = false;
}
public void ShowControl()
{
PopulateTable();
this.Visible = true;
}
private void PopulateTable()
{
List<SomeEntity> collection = new List<SomeEntity>()
{
new SomeEntity()
{
Date = DateTime.Now.ToFileTimeUtc().ToString(),
Col1 = "Col 1", Col2 = "Col 2", Col3 = "Col 3"
},
new SomeEntity()
{
Date = DateTime.Now.ToFileTimeUtc().ToString(),
Col1 = "Col 1", Col2 = "Col 2", Col3 = "Col 3"
},
new SomeEntity()
{
Date = DateTime.Now.ToFileTimeUtc().ToString(),
Col1 = "Col 1", Col2 = "Col 2", Col3 = "Col 3"
}
};
PagedDataSource pds = new PagedDataSource(){DataSource= collection};
myRepeater.DataSource = pds;
myRepeater.DataBind();
}
As you can see there's a Repeater control with ID="myRepeater. Here is the html code (here again i put divs to follow the structure of bootstrap's modal):
<div class="myPopup popup-someEntity">
<!-- ============ Modal header ============ -->
<div class="modal-header">
<!-- == Close button == -->
<asp:LinkButton ID="lnkBtnClose" runat="server" ToolTip="Close"
CssClass="close" aria-hidden="true"
OnClick="btnClose_Click">
<i class="fa fa-remove"></i>
</asp:LinkButton>
<!-- == /Close button == -->
<h4 class="modal-title" id="myModalLabel">
My Modal Popup
</h4>
</div>
<div class="row-separator"></div>
<!-- ============ /Modal header ============ -->
<!-- === Table == -->
<div class="div-row">
<div class="row-fluid table-responsive">
<table class="table table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Date UTC</th>
<th>Col2</th>
<th>Col3</th>
<th>Col4</th>
</tr>
</thead>
<tbody>
<asp:Repeater ID="myRepeater" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("Date") %></td>
<td><%# Eval("Col1") %></td>
<td><%# Eval("Col2") %></td>
<td><%# Eval("Col3") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</tbody>
</table>
</div>
</div>
<!-- === /Table == -->
</div>
Finally generated html (with the table filled and the visible popup) will be returned to the client.As you've noticed the html code of the popup control has a div as a container which has to css classes, myPopup and popup-someEntity, i use the first as a selector(all div with that class will be displayed as a popup) and i use the second to set the width of the popup).
Now in the client using jquery i do this:
$(document).ready(function () {
//This uses bootstrap 3 modal:
if ($(".myPopup").length > 0) {
$(".myPopup").each(function (popupIndex) {
var $curPopup = $(this);
var $modalBody = $curPopup.parent();
var $modalContent = $modalBody.parent();
var $modalDialog = $modalContent.parent();
var $modal = $modalDialog.parent();
if ($curPopup.children('.modal-header').length > 0) {
//Hide external modal-headers:
if ($modalContent.children('.modal-header').length > 0) {
$modalContent.children('.modal-header').each(function () {
var $externModalHeader = $(this);
$externModalHeader.css({ 'display': 'none' });
});
}
}
var contentWidth = $curPopup.width();
contentWidth += 40; //add padding width
$modalDialog.width(contentWidth);
$modal.modal({ show: true, backdrop: "static", keyboard: false }).draggable({
handle: ".modal-header"
}); /*.on('shown.bs.modal', function () {
$modalContent.css({ width: contentWidth + 'px', height: 'auto', 'max-height': '100%' });
});*/
});//each
}//if myPopup
});//ready
And voilá, the popup is displayed!.
I've omitted a few things(like bootstrap, font-awesome,.. i've used in the example) but i'm sure you understand quickly reviewing the code.
You can download the code from here:
Modal popup with webforms C# (Monodevelop project)
I need to open a page like a modal dialog .I find an exemple on net but it doesn't work.
In the main page I have this code:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Button Text ="Add New Course" runat="server" ID="btnAddCourse" OnClientClick="showPanel('dialog');return false;"/>
<script type="text/javascript">
function showPanel(panelID) {
$panel = $('#' + panelID);
$.ajax({
url: "/AddNew.aspx",
type: "GET",
dataType: "html",
async: false,
data: { "param": "abcd"
},
success: function (obj) {
// obj will contain the complete contents of the page requested
// use jquery to extract just the html inside the body tag
$content = $(obj).find('body').html();
// then update the dialog contents with this and show it
$panel.html($content);
$panel.dialog();
}
});
}
</script>
<div id="dialog">
</div>
</asp:Content>
When I click the button I need to open the page below .I receive an error that tell that element $ is not recognized.I don't know exactly who is element panel .Must I add a panel control ,but where ?
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="AddNew.aspx.cs" Inherits="WebApplicationDialog.AddNew" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Add New Course </title>
</head>
<body>
<form >
<div id="div1">
<table>
<tr><td colspan="3"> <asp:Label ID="lblCourse" runat="server" Text="Add New Course"></asp:Label></td></tr>
<tr><td colspan="3"> </td></tr>
<tr>
<td style="width:40%"> <asp:Label ID="lblName" runat="server" Text="Course Name" ></asp:Label></td>
<td style="width:20%"> </td>
<td style="width:40%">
<input id="txtName" type="text" />
</td>
</tr>
<tr>
<td style="width:40%"> <asp:Label ID="lblDescription" runat="server" Text="Description" ></asp:Label></td>
<td style="width:20%"> </td>
<td style="width:40%">
<input id="txtDescription" type="text" />
</td>
</tr>
<tr><td colspan="3" style="float:right">
<input value ="Save" id="btnSave" type="submit" /> </td></tr>
</table>
</div>
</form>
</body>
</html>
Can somebody help me with this code ,to make it works ?
Thanks
It looks like you are trying to use JQuery to load a page content into a panel but if I'm reading your code right you may not have included the JQuery library, you need to include this line of code in the <head> of your html code. You are also using JQueryUI dialog and will need to reference the JQueryUI library
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
For Example
<head>
<title>Page Title</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<head>
EDIT: I also notice you are using the dialog, which is in JQuery UI, pleasse make sure you reference JQuery UI toolkit as well
EDIT: Have stripped your code into jsFiddle: http://jsfiddle.net/EhPk7/1/
this seems to work for me
You need to add jquery lib reference.
At the top of a page:
<script src="http://code.jquery.com/jquery-1.8.2.min.js"/>
Include jQuery.
Change this line -> $panel = $('#' + panelID); to -> $panel = $('#div1'); and see if it works.
Consider adding jQuery script references on your page, above the jQuery Code that you are using.
Also, add reference jQuery UI
Download jQuery
There is a boolean property/setting called modal on the jQueryUI dialog, this will create a modal-type dialog.
I myself use this:
d.dialog({
autoOpen: true,
closeOnEscape: false,
closeText: '',
modal: true,
draggable: false,
resizable: false,
width: (window.document.width * 0.75),
dialogClass: 'popup loading',
title: 'title'),
});
when you wrap this sort of function in the
$(document).ready(function() {
})
it should popup the moment the DOM is ready..
I have been searching on here on the web everywhere for two DAYS to find this. As of yet I have not found what I need. I am not sure if it is because I am doing something weird with AJAX or what but here is my problem if you can help please do.
I am trying to make a website that only has multiple pages but uses AJAX and JQuery to give the illusion of having one page. The URL does not change like it is supposed to but when I try to create a salesperson or login using the AJAX loaded page it does not work. It looks like it does but it does not actually submit the data input as the code behind is never hit on the separate pages. The following code is my AJAX page.
/// <reference path="jquery-1.8.2-vsdoc.js" />
$(document).ready(function () {
$('#ViewAllUsers').click(function () {
$.ajax({
type: 'POST',
url: "/ViewAllUsers(test).aspx",
success: function (result) {
var main = $('#Main');
main.html($('#Main', result).html());
}
});
});
$('#Button1').click(function () {
$.ajax({
type: 'POST',
url: "/Login.aspx",
success: function (result) {
var main = $('#Main');
main.html($('#Main', result).html());
}
});
});
$('#AddItem').click(function () {
$.ajax({
type: 'POST',
url: "/admin/AddItem.aspx",
success: function (result) {
var main = $('#Main');
main.html($('#Main', result).html());
}
});
});
$('#CreateSalesAccount').click(function () {
$.ajax({
type: 'POST',
url: "/admin/CreateSalesAccount.aspx",
success: function (result) {
var main = $('#Main');
main.html($('#Main', result).html());
}
});
});
$('#ViewAllOrderHistory').click(function () {
$.ajax({
type: 'POST',
url: "/admin/ViewOrderHistory.aspx",
success: function (result) {
var main = $('#Main');
main.html($('#Main', result).html());
}
});
});
});
This code is the admin page which is the page that uses the AJAX buttons to go to the other pages while staying on the admin page.
<%# Page Title="" Language="vb" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="AdminPage.aspx.vb" Inherits="PyriteGoldPresentation.AdminPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script src="../Scripts/jquery-1.8.2.js" type="text/javascript"></script>
<script src="../Scripts/PyriteGoldAjax.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id = "Main">
<input type="button" id="ViewAllUsers" value="View All Users" />
<input type="button" id="AddItem" value = "Add Item" />
<input type="button" id="CreateSalesAccount" value="Create A Sales Account" />
<input type="button" id="ViewAllOrderHistory" value="View Order History" />
</div>
</asp:Content>
And Finnaly here is the create salesman page and the code behind it.
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="CreateSalesAccount.aspx.vb" Inherits="PyriteGoldPresentation.CreateSalesAccount"%>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script src="../Scripts/jquery-1.8.2.js" type="text/javascript"></script>
<script src="../Scripts/PyriteGoldAjax.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="Main">
<div style="width: 400px; margin-left:auto; margin-right:auto;">
<div class="row">
<h2>
Create Sales Account
</h2>
</div>
<div class="row">
<span class="column1">
<asp:Label ID="FirstNameLabel" runat="server" Text="First Name"/>
</span>
<span class="column2">
<asp:TextBox ID="FirstNameTextField" runat="server" Width="137px"/>
</span>
<span class="column3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*Required Field"
ControlToValidate="FirstNameTextField"/>
</span>
</div>
<div class="row">
<span class="column1">
<asp:Label ID="LastNameLabel" runat="server" Text="Last Name"/>
</span>
<span class="column2">
<asp:TextBox ID="LastNameTextBox" runat="server" Width="137px"/>
</span>
<span class="column3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*Required Field" ControlToValidate="LastNameTextBox"/>
</span>
</div>
<div class="row">
<span class="column1">
<asp:Label ID="EmailLabel" runat="server" Text="E-Mail Address"/>
</span>
<span class="column2">
<asp:TextBox ID="EmailTextBox" runat="server" Width="134px"/>
</span>
<span class="column3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*Required Field" ControlToValidate="EmailTextBox"/>
</span>
</div>
<div class="row">
<span class="column1">
<asp:Label ID="VerifyEmailLabel" runat="server" Text="Verify E-Mail"/>
</span>
<span class="column2">
<asp:TextBox ID="VerifyEmailTextBox" runat="server" Width="136px"/>
</span>
<span class="column3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="*Required Field" ControlToValidate="VerifyEmailTextBox"/>
</span>
</div>
<div class="row">
<span class="column1">
<asp:Label ID="PasswordLabel" runat="server" Text="Password"/>
</span>
<span class="column2">
<asp:TextBox ID="PasswordTextBox" runat="server" Width="138px"
TextMode="Password"/>
</span>
<span class="column3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="*Required Field" ControlToValidate="PasswordTextBox"/>
</span>
</div>
<div class="row">
<span class="column1">
<asp:Label ID="VerifyPasswordLabel" runat="server" Text="Verify Password"/>
</span>
<span class="column2">
<asp:TextBox ID="VerifyPasswordTextBox" runat="server" Width="138px"
TextMode="Password"/>
</span>
<span class="column3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="*Required Field" ControlToValidate="VerifyPasswordTextBox"/>
</span>
</div>
<div class="row" style="color:Red;">
<asp:CompareValidator ID="EmailValidator" runat="server" ErrorMessage="**E-mail Feilds Must Match" ControlToCompare="EmailTextBox" ControlToValidate="VerifyEmailTextBox"/><br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="**E-mail Addresses must follow the pattern user#domain.com" ControlToValidate="EmailTextBox"
ValidationExpression="\w+([-+.']\w+[-]*)*#\w+([-.]*\w+)*\.\w+([-.]\w+)*"/><br />
<asp:CompareValidator ID="PasswordValidator" runat="server" ErrorMessage="**Password Fields Must Match" ControlToCompare="PasswordTextBox" ControlToValidate="VerifyPasswordTextBox"/>
</div>
<div>
<asp:Button ID="SubmitButton" runat="server" Text="Submit" OnClick="SubmitButton_Click" />
</div>
</div>
</div>
</asp:Content>
Code Behind
Imports PyriteGoldBLL
Imports PyriteGoldModel
Public Class CreateSalesAccount
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("permissionValue") <> 3 Then
Response.Redirect("~/Home.aspx")
End If
End Sub
Protected Sub SubmitButton_Click(sender As Object, e As EventArgs) Handles SubmitButton.Click
Dim userLogic As New UserLogic()
Dim user As New User()
With user
.FirstName = FirstNameTextField.Text
.LastName = LastNameTextBox.Text
.Email = EmailTextBox.Text
.Password = PasswordTextBox.Text
.Activated = True
.Permission = 2
End With
userLogic.CreateUser(user)
End Sub
End Class
I'm not 100% following what you're trying to achieve.. though making a stab at this anyway :)
You're trying to call an actual page in your AJAX, rather than trying to call a webmethod - which is what you need to do.. you can't call what you're trying to call in the way you're trying to call it...
I would suggest you create a web service which has all the methods you need, such as login, addItem etc. These methods will need to take in the properties you need, I.E Login may need a username and password.
If you rather not create a web service then you will have to put all these methods into the same page that the ajax is on.
So for example: for your ajax login
The URL is to your web service, followed by '/' followed by the method name.
$('#Button1').click(function () {
$.ajax({
type: 'POST',
url: "/MyWebservice.asmx/Login",
data: "{'username':'" + YourUserNameVar + "', 'password':'" + YourPasswordVar +"'}",
success: function (result) {
var main = $('#Main');
main.html($('#Main', result).html());
}
});
});
The method to receive this call would look something like:
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function Login(ByVal username As String, ByVal password as string) As Object
'' Do your login here and return whatever it is you need to return
'' i have used 'Object' for this function by way of example
End Function
This answer could of course be fleshed out with far more info, though this is more intended to get you started and on the right path.
UPDATE:
You need to learn a little about consuming web methods/web services with AJAX. Have a look at this simple tutorial. shows all the steps you need to get started :)
For some reason, the value returned by the Modal Dialog box is always "undefined".
My Main page (aspx):
<%# Page Title="Home Page" Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html>
<head></head>
<body>
<script type="text/javascript">
function openWindows () {
var getval;
getval = window.showModalDialog('../WebSite/popups/uploader.htm');
document.getElementById("Input").value = getval;
}
</script>
<input id="Input" runat="server" />
<input type="button" id="Button1" runat="server" onclick="openWindows()" value="Choose Image"/>
</form>
</body>
</html>
So in this case, the value of getval is always "undefined"
My Dialog Box (HTML) Code:
<html>
<head>
<script type="text/javascript">
function ReturnValues() {
var objfile = document.getElementById("fileup").value
document.getElementById("TxtInput").value = objfile
var vReturnValue = document.getElementById("TxtInput").value;
window.ReturnValue = vReturnValue;
window.close();
}
</script>
</head>
<body>
<form id="Formuploader" method="post" runat="server">
<input id="TxtInput" type="hidden" runat="server" /><br />
<button id="btnSaveImage" runat="server" onclick="ReturnValues()">Save Image</button>
</form>
</body>
</html>
Here, ReturnValue does have the required value. But as soon as the ModalDialog closes, the getval variable in the main window becomes undefined.
Any help is greatly appreciated.
Thanks!
when you return value, do it this way:
window.returnValue = vReturnValue;
use lowercase returnValue, not ReturnValue.
also, your modal dialog is not closing. to fix that, change your button to a link.
<a href="#" id="btnSaveImage" runat="server" target="_self" onclick="ReturnValue()">
Save Image</a>
Try this:
window.opener.document.getElementById("Input").value = getval;
edit 2 -
To recreate - (I hope)
Create an empty asp.net project, add a default.aspx, and an about.aspx
use this code for the default.aspx file:
http://pastebin.com/4Ri1BufM
and this for about.aspx
http://pastebin.com/Ni9dZL7c
Build, and run sieve against it. Click the button, then the link. Sieve should now list 1 memory leak.
This simple layout puts a server button inside a panel. If you click it, and then the "Leave" link, sIEve reports 1 memory leak:
http://localhost:2605/Default.aspx (1 reference)
<INPUT value="partial postback" type=submit name=ctl01 >
Aspx source:
<%# Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="LeakTestProject._Default" %>
<html>
<head>
<title></title>
</head>
<body>
<form id="Form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button Text="partial postback" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
<a href="SomeOtherPage.aspx" >leave</a>
</body>
</html>
I've think I've tracked down a memory leak in my application to this source.
Would anyone be able to explain why this is happening, and what to do to fix it?
(Note - there is no server side code running)
edit-
Here is the generated html:
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="Default.aspx" id="Form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTUzNzM3OTMxMmRk27mKixZYS2MtHiuw7SZF6+1A/CkWRnnarcN2a05yCJs=" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['Form1'];
if (!theForm) {
theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/WebResource.axd?d=_lxNoU5aYdEC_WWnUhGTN0VgFQnwFJ1fkZBkPhUGNITY1Tt87f4CGSPd9dhq2TD9I8lv5ljTGi956KpbHSLq3ebld0t7nKLON7Hc04CCAwA1&t=634525784292792916" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=0VE3fsyoY2cTFnat6m0YjE4OCCjVV0jmjSC6wigMBEOHyKW8kewBrhtJnBFIn73VSWcGW45QXwelC5m-1iZoornC8qWpZ-kXP-Y38e49qW1TbssOgo419ZWtVHSVmIpSg9CvXOQzUBClAjuHORyX5Q2&t=ffffffffbd2983fc" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
//]]>
</script>
<script src="/ScriptResource.axd?d=DBlWOXkmp0ycsSicGEZhACmLuhW1VF8BppK-Uj8ijyjhFxx7MTG8NW0gLl3IJ6TyEo2rAMfLCQ9rO_bk2wDCcpyT3Df6CN-TLMAA575gUNAjTSzC6U1koagV2FYRmu4TNsAgoEjhkN6fJX3lENf7Bw2&t=ffffffffbd2983fc" type="text/javascript"></script>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLZvOXNBgKiwImNCx8fSMXEwq+V+5yrnoaTcidPwoJw3ebm6DJQ1D3fVVAL" />
</div>
<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', 'Form1', ['tUpdatePanel1','UpdatePanel1'], [], [], 90, '');
//]]>
</script>
<div id="UpdatePanel1">
<input type="submit" name="ctl01" value="partial postback" />
</div>
</form>
<a href="About.aspx" >leave</a>
</body>
</html>
According to http://www.codeproject.com/KB/ajax/jqmemleak.aspx there is a memory leak that sounds a lot like what you are experiencing.
See "Iteration 2 - Memory Leak"
Using a tool called 'SIEve' he states 'You can see that every time I click refresh, it creates a new set of input elements without destroying the previous ones. '
His fix was a JQuery plugin that calls into the Update panel cleanup hooks. You could potentially try this?
(function($) {
$.fn.Disposable = function(cln) {
return this.each(function() {
var el = this;
if (!el.dispose) {
el.dispose = cleanup; // will be called by
// Microsoft for cleanup
$(window).bind("unload", cleanup);
}
function cleanup() {
if (!el)
return;
$(el).unbind();
$(window).unbind("unload", cleanup);
el.dispose = null;
el = null;
};
});
};
})(jQuery);
function add() {
$get('res').value =
parseInt($get('i1').value) + parseInt($get('i2').value);
}
Sys.Application.add_load(function() {
$('.num').change(add).Disposable();
});
could you please try this change:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script>
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(my_init);
function my_init() {
document.getElementById("UpdatePanel1").innerHTML = "";
}
</script>