I'm trying to setup a couple of dropdown lists that are populated from the database via Ajax and am trying to use jQuery to do it. I found an example @
http://www.joe-stevens.com/2010/02/23... and modified it so that it was accessing the web service instead of his default code. When I run the changes on his project everything works great but when I run it in my module I get a 404 error when it tries to get the POST url and I'm looking for ideas on how to get around the problem. My code is below....
LOGIN.ASCX
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Login.ascx.cs" Inherits="JRSSB.Modules.Banklab.Login" %>
<%@ Register TagPrefix="dnn" Assembly="DotNetNuke" Namespace="DotNetNuke.UI.WebControls"%>
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
<div id="divBanklabForm" runat="server">
<div class="Normal Banklab_Instructions">
<asp:Label id="lblInstructions" AssociatedControlID="divBanklabBlock" runat="server"></asp:Label>
</div>
<div class="SubHead Banklab_SectionHead">
<dnn:Label id="plLoginInfo" runat="server" ControlName="divBanklabBlock"></dnn:Label>
</div>
<div id="divBanklabBlock" runat="server" class="Banklab_InfoBlock">
<table>
<tr>
<th>
<dnn:label id="plBranch" runat="server" controlname="ddlBranch" suffix=":"></dnn:label>
</th>
<td>
<select id="ddlBranch">
</select>
</td>
</tr>
<tr>
<th>
<dnn:label id="plTeller" runat="server" controlname="ddlTellerNumber" suffix=":"></dnn:label>
</th>
<td>
<select id="ddlTeller">
</select>
</td>
</tr>
<tr>
<td align="center"><asp:Button ID="cmdLogin" runat="server"
Text="Button" ResourceKey="cmdLogin" CssClass="StandardButton"
onclick="CmdLoginClick"/></td>
</tr>
</table>
</div>
</div>
Login.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using System.Web.Services;
using System.Collections;
using System.Data;
// ReSharper disable CheckNamespace
namespace JRSSB.Modules.Banklab
// ReSharper restore CheckNamespace
{
public partial class Login : BanklabModuleBase
{
#region "Constants"
const string CoreScriptRoot = "~/resources/shared/scripts/jquery/";
#endregion
protected void Page_Load(object sender, EventArgs e)
{
//RegisterJQueryScript("jquery.min.js", true);
DotNetNuke.Framework.jQuery.RequestRegistration();
RegisterJavascript();
//RegisterJQueryScript("/js/jquery.login.js");
}
#region "Private Methods"
private void RegisterJQueryScript(string scriptName, bool isCore = false)
{
var scriptRoot = (isCore ? CoreScriptRoot : this.TemplateSourceDirectory).ToString();
const string scriptFormat = "<script type=\"text/javascript\" src=\"{0}\" ></script>";
var headscript = new LiteralControl
{
Text = string.Format(scriptFormat, ResolveUrl(scriptRoot + scriptName))
};
Page.Header.Controls.Add(headscript);
}
private void RegisterJavascript()
{
//Register the ETH script
string jQueryEthScriptPath = this.TemplateSourceDirectory + "/js/jquery.login.js";
Page.ClientScript.RegisterClientScriptInclude("jquery.login", jQueryEthScriptPath);
}
#endregion
#region "Web Methods"
[WebMethod]
public static ArrayList GetBranches()
{
var branch = new ServiceAccess();
var ds = branch.GetBranches();
var arrBranches = new ArrayList();
foreach (DataRow dataRow in ds.Tables[0].Rows)
{
arrBranches.Add(new { Value = dataRow["BranchNumber"], Display = dataRow["BranchNumber"] });
}
return arrBranches;
}
[WebMethod]
public static ArrayList GetTellers(int BranchID)
{
if (BranchID <= 0)
{
throw new ApplicationException("Invalid Branch ID");
}
var teller = new ServiceAccess();
var ds = teller.GetTellers(BranchID);
var arrTellers = new ArrayList();
foreach (DataRow dataRow in ds.Tables[0].Rows)
{
arrTellers.Add(new { Value = dataRow["TellerNumber"], Display = dataRow["TellerNumber"] });
}
return arrTellers;
}
#endregion
protected void CmdLoginClick(object sender, EventArgs e)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using System.Web.Services;
using System.Collections;
using System.Data;
// ReSharper disable CheckNamespace
namespace JRSSB.Modules.Banklab
// ReSharper restore CheckNamespace
{
public partial class Login : BanklabModuleBase
{
#region "Constants"
const string CoreScriptRoot = "~/resources/shared/scripts/jquery/";
#endregion
protected void Page_Load(object sender, EventArgs e)
{
//RegisterJQueryScript("jquery.min.js", true);
DotNetNuke.Framework.jQuery.RequestRegistration();
RegisterJavascript();
//RegisterJQueryScript("/js/jquery.login.js");
}
#region "Private Methods"
private void RegisterJQueryScript(string scriptName, bool isCore = false)
{
var scriptRoot = (isCore ? CoreScriptRoot : this.TemplateSourceDirectory).ToString();
const string scriptFormat = "<script type=\"text/javascript\" src=\"{0}\" ></script>";
var headscript = new LiteralControl
{
Text = string.Format(scriptFormat, ResolveUrl(scriptRoot + scriptName))
};
Page.Header.Controls.Add(headscript);
}
private void RegisterJavascript()
{
//Register the ETH script
string jQueryEthScriptPath = this.TemplateSourceDirectory + "/js/jquery.login.js";
Page.ClientScript.RegisterClientScriptInclude("jquery.login", jQueryEthScriptPath);
}
#endregion
#region "Web Methods"
[WebMethod]
public static ArrayList GetBranches()
{
var branch = new ServiceAccess();
var ds = branch.GetBranches();
var arrBranches = new ArrayList();
foreach (DataRow dataRow in ds.Tables[0].Rows)
{
arrBranches.Add(new { Value = dataRow["BranchNumber"], Display = dataRow["BranchNumber"] });
}
return arrBranches;
}
[WebMethod]
public static ArrayList GetTellers(int BranchID)
{
if (BranchID <= 0)
{
throw new ApplicationException("Invalid Branch ID");
}
var teller = new ServiceAccess();
var ds = teller.GetTellers(BranchID);
var arrTellers = new ArrayList();
foreach (DataRow dataRow in ds.Tables[0].Rows)
{
arrTellers.Add(new { Value = dataRow["TellerNumber"], Display = dataRow["TellerNumber"] });
}
return arrTellers;
}
#endregion
protected void CmdLoginClick(object sender, EventArgs e)
{
}
}
}
jquery.login.js
jQuery(document).ready(function () {
jQuery.ajax({
type: "POST",
url: location.href + "/GetBranches",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
jQuery("#ddlBranch").get(0).options.length = 0;
jQuery("#ddlBranch").get(0).options[0] = new Option("Select Branch", "-1");
jQuery.each(msg.d, function(index, item) {
jQuery("#ddlBranch").get(0).options[jQuery("#ddlBranch").get(0).options.length] = new Option(item.Display, item.Value);
});
jQuery("#ddlBranch").bind("change", function() {
GetTellers(jQuery(this).val());
});
},
error: function() {
Failed to load Branches");
}
});
});
function GetTellers(BranchID) {
if (BranchID > 0) {
jQuery("#ddlTeller").get(0).options.length = 0;
jQuery("#ddlTeller").get(0).options[0] = new Option("Loading Tellers", "-1");
jQuery.ajax({
type: "POST",
url: location.href + "/GetTellers",
data: "{BranchID:" + BranchID + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
jQuery("#ddlTeller").get(0).options.length = 0;
jQuery("#ddlTeller").get(0).options[0] = new Option("Select Teller Number", "-1");
jQuery.each(msg.d, function(index, item) {
jQuery("#ddlTeller").get(0).options[jQuery("#ddlTeller").get(0).options.length] = new Option(item.Display, item.Value);
});
},
error: function() {
jQuery("#ddlTeller").get(0).options.length = 0;
Failed to load names");
}
});
}
else {
jQuery("#ddlTeller").get(0).options.length = 0;
}
}