When Ext.Net App.direct is defined? - javascript

I have a problem using Ext.Net 2.5 and App.Direct:
Ext.onReady(function() {
App.direct.GetAll({
success: function (result) {
currentMessageId = result;
}
});
});
The problem exist in body onload too.
When I Call the direct method in Ext.onReady it gives me this error: "Cannot Call GetAll of undefined."
But, when I call it instead a click button handler it works without problem.
So, the question is:
When App.direct is defined?

In the Page Sources you could see the following.
Ext.onReady(function () {
Ext.ns("App.direct");
Ext.apply(App.direct, {
TestDirectMethod: function (config) {
return Ext.net.DirectMethod.request("TestDirectMethod", Ext.applyIf(config || {}, {}));
}
});
});
It is how a DirectMethod is rendered to a browser.
As you can see it is inside an Ext.onReady function. So, your onReady function is executed before that.
You can force rendering of our onReady function before your one using a ResourcePlaceHolder.
<%# Page Language="C#" %>
<%# Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
[DirectMethod]
public void TestDirectMethod()
{
X.Msg.Alert("DirectMethod", "Hello from Server!").Show();
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
<ext:ResourcePlaceHolder runat="server" Mode="Script" />
<script>
Ext.onReady(function() {
App.direct.TestDirectMethod();
});
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
</form>
</body>
</html>
Here is a description of possible options for a ResourcePlaceHolder's Mode.

Related

Protocol Check is not invoking from success callback of previous protocol check

It behaves inconsistent with respect to browsers.
Google Chrome: Can invoke first one but cannot invoke another one.
$(function () {
$("div[href]").click(function (event) {
debugger;
window.protocolCheck("abcd:",
function () {
console.log('err1')
}, function () {
console.log('succ1');
window.protocolCheck("xyz:",
function () {
console.log('err2');
}, function () {
console.log('succ2');
});
});
});
});
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Custom Protocol Detection</title>
</head>
<body id="abcd">
<h1>Click one of these labels:</h1>
<div href="blahblah:randomstuff" style="background-color:aquamarine">
Non-exist protocol
</div>
<div href="mailto:johndoe#somewhere.com" style="background-color:aqua">
Send email
</div>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://github.com/ismailhabib/custom-protocol-detection/blob/master/protocolcheck.js"></script>
<script src="example.js"></script>
</body>
</html>
I want to validate in user registry that some protocol exist.
If registry not found we download it if found we invoke next protocol.
Library https://github.com/ismailhabib/custom-protocol-detection/blob/master/protocolcheck.js
And for invoking can we use protocol check library.
The second callback is called on success. So, the first check fails, then the second check code will not be invoked.

Service Call in client Side

I need to call the service and retrieve the resulted data in call back function from it but I am getting js error:
Uncaught ReferenceError: InvoiceHTMLService is not defined.
Please help - below are my pages and class
My Aspx page
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="InvoiceHTML.aspx.vb" Inherits="WebApplication2.InvoiceHTML" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Web Service call from client-side JavaScript</title>
<script type="text/javascript">
function SendRequest() {
debugger;
InvoiceHTMLService.GetBillInvoiceHtmlData();
}
function OnComplete(arg) {
alert(arg);
}
function OnTimeOut(arg) {
alert("timeOut has occured");
}
function OnError(arg) {
alert("error has occured: " + arg._message);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/Service/InvoiceHTMLService.asmx" />
</Services>
</asp:ScriptManager>
<div>
<input type="text" value="" id="MyTextBox" />
<input type="button" value="Send Request to the Web Service"
id="RequestButton" onclick="return SendRequest()" />
</div>
</form>
</body>
</html>
my asmx page
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO
Imports ClassLibrary1
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService()> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ScriptService()> _
Public Class InvoiceHTMLService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetBillInvoiceHtmlData() As Object
Dim objDAOBill As DAOInvoice
Dim Obj As Object
objDAOBill = New DAOInvoice()
Obj = objDAOBill.GetBillInvoiceHtmlData()
Return Obj
End Function
End Class
I got the answer for it thanks everyone, I am posting the answer so it may can help others the service call from client side can be done by using the complete class name present in .asmx page.In my Case
<%# WebService Language="vb" CodeBehind="InvoiceHTMLService.asmx.vb" Class="App.InvoiceHTMLService" %>
So I have to call the service in following way:
function SendRequest() {
App.InvoiceHTMLService.GetBillInvoiceHtmlData(callback);
}

Calling same js function on pageload and on button click and displaying both functions called

I have a javascript function and I want to call the same function twice.
Once on page load and once on a button click.
I want the output as the function on page load will keep on running in backend and
display output and when button is clicked again function is called and its output
gets displayed.
Finally both functions output should be displayed.
This is what I have written but am not getting the output.
For e.g.
Javascript file: n.js
function webservice{
for(i=0;i<10;i++)
{
alert("some msg");
`enter code here`
}
html file n.html
<html>
<head>
<script type = "text/javascript" src="n.js"></script>
<script type="text/javascript">
window.onload=function() {
webservice();
}
</script>
</head>
<body>
<input id="button" type = "button" name = "webservice" value = "Call Webservice"
onClick="webservice()" />
</body>
</html>
Following code is working on my machine. I think you are missing () for function webservice(). so instead of webservice use webservice()
<html>
<head>
<script>
function webservice()
{
for(i=0;i<10;i++)
{
alert("some msg");
}
}
window.onload=function()
{
webservice();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<input id="webservice" type = "button" name = "webservice" value = "Call Webservice" onClick="webservice()" />
</body>
</html>
Update:
if you write your onload function like this then you will be able to execute call 1 and call 2, butcall 2 will begin when call 1 loop is completed.
window.onload=function()
{
webservice('onload'); //call 1
document.getElementById("webservice").click(); //call 2
}
I think you code may be in wrong format.
function webservice{
for(i=0;i<10;i++)
{
alert("some msg");
`enter code here`
}
change to
function webservice(){
for(i=0;i<10;i++)
{
alert("some msg");
//enter code here
}
just add () after webservice. like webservice().

CamanJS image manipulation, strange error

i'm using CamanJS to do some images manipulation with javascript, and I have two similar really simple scripts, the first works well, the second not (and this is the script i need working).
This is the first working:
<!DOCTYPE html>
<html lang="en">
<head>
<title>CamanJS Testing Playground</title>
<script type="text/javascript" src="caman.full.min.js"></script>
</head>
<body>
<button onclick="filtraPhoto();">MODIFICA</button><br />
<img id="smallImage" />
<script>
var immagine;
var smallImage = document.getElementById('smallImage');
smallImage.src = "test1_600.jpg";
immagine = Caman("#smallImage", function () {});
function filtraPhoto() {
immagine.brightness(10).contrast(500).render(function () {
alert("Done!");
});
}
</script>
</body>
</html>
This is the second not working, it return in firebug the error: TypeError: this.c.pixelData is undefined
<!DOCTYPE html>
<html lang="en">
<head>
<title>CamanJS Testing Playground</title>
<script type="text/javascript" src="caman.full.min.js"></script>
<script>
var immagine;
function carica()
{
var smallImage = document.getElementById('smallImage');
smallImage.src = "test1_600.jpg";
immagine = Caman("#smallImage", function () {});
}
function filtraPhoto() {
immagine.brightness(10).contrast(500).render(function () {
alert("Done!");
});
}
</script>
</head>
<body>
<button onclick="carica();">carica immagine</button><br />
<button onclick="filtraPhoto();">MODIFICA</button><br />
<img id="smallImage" />
</body>
</html>
Any help please?
It runs just fine in both Firefox and Chrome for me. In my limited experience, this.c.pixelData typically comes when your conversion to a CamanInstance was not successfully created.
This can be because of many things, but one that isn't expected is that CamanJS won't let you use the same html identifier (class or id) for more than one object, even if you've swapped them out. So if you're running the two scripts above on the same page, it will cause errors.
Sorry, without being able to reproduce your error, it's hard to help more than that.

Current context value is not rendered from Usercontrol to .aspx page

i have default.aspx page and one user control.
usercontrol is having following code for multiple file uploads.
now the problem is when i add a file for upload that current context file is not giving me any value it is still zero i guess because it is rendering from user control.
what should i do?
My Usercontrol UPLOAD.ASCX
<%# Control Language="C#" AutoEventWireup="true" CodeFile="FileUpload.ascx.cs" Inherits="FileUpload" %>
<script type="text/javascript" src="_scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
var i = 1;
$(document).ready(function () {
$("#addfile").click(function () {
$("#dvfiles").append("<input name=" + i + "fu type=file /><a href=#>remove</a><br>");
i++;
});
$("#dvfiles a").live('click', function () {
$(this).prev("input[type=file]").remove();
$(this).remove();
});
});
$(document).submit(function () {
var flag = true;
$("#dvfiles input[type=file]").each(function () {
if ($(this).val() == "") {
$(this).css("background", "Red");
flag = false;
}
});
return flag;
});
</script>
<div id="Fileuploader">
Attach a file..<br />
<asp:Label ID="lblMessage" runat="server"></asp:Label><br />
<asp:Button ID="btnUpload" runat="server" Text="Upload"
onclick="btnUpload_Click" />
</div>
UPLOAD.ASCX.CS
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
HttpFileCollection filecolln = Request.Files;
//here i don't get values of current files.
// this is zero. because of this following if condition failed
//please help here
if (filecolln.Count > 0)
{
for (int i = 0; i < filecolln.Count; i++)
{
HttpPostedFile file = filecolln[i];
if (file.ContentLength > 0)
{
file.SaveAs(ConfigurationManager.AppSettings["FilePath"] + System.IO.Path.GetFileName(file.FileName));
}
}
lblMessage.Text = "Uploaded Successfully!";
}
else
{
lblMessage.Text = "No files selected!";
}
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
}
}
Default.aspx code
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<%# Register TagPrefix="ucFileuploader" tagName="Fileuploader" src="FileUpload.ascx" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ucFileuploader:Fileuploader ID="Fileuploder" runat="server" />
</div>
</form>
</body>
</html>
The problem is that you are using javascript an id names.
so when you have control with id addfile in .aspx it is rendered as is,
but when you have control with id addfile in user control with id Fileuploader,
than the rendered id is Fileuploader_addfile,
so change id name in java script with the proper id.
To chechk what is name of rendered id, open page in browser, open source of the page and find you element and copy id into java script.
Change all ids in java script with rendered id names.
I would suspect it could be this line:
<script type="text/javascript" src="_scripts/jquery-1.4.1.min.js"></script>
Which should be:
<script type="text/javascript" src="/_scripts/jquery-1.4.1.min.js"></script>

Categories

Resources