I have an html form on a page that sends information to an .asp file. In the .ASP file, I am trying to write in the javascript version of asp to retrieve the information sent by the form. What is the code for doing this? I have tried Request.Querystring, but this does not work. I want to use the javascript version as that is what I am familiar with. Please do not answer this with the VBSCRIPT version.
Regardless of what language you use, the asp collection for form values is going to be querystring for GET and form for POST.
<%# language="Javascript" %>
<script language="Javascript" runat="server">
Response.Write("Script Engine: " + ScriptEngine() + " " +
ScriptEngineMajorVersion() + "." +
ScriptEngineMinorVersion() + " build " +
ScriptEngineBuildVersion());
var p1 = Request.QueryString('p1') + '';
if (p1 != 'undefined') {
Response.Write ("<br/><br/>you said: " + p1);
}
else {
Response.Write ("<br/><br/>If you append a query string param called 'p1', "+
"it will be echoed here.");
}
</script>
Related
Is is possible to update values of javascript inside the update panel
I am trying it in update panel so that the values get refreshed without postback
int used=50,unused=70;
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<script>
var data = [{
values: [<%Response.Write(unused);%>,<%Response.Write(used);%>],
labels: ['Unused', 'Used '],
}];
Plotly.newPlot('myDiv', data);
</script>
</asp:UpdatePanel>
You cannot use Response.Write (or <%= unused %>) in an UpdatePanel. It will give the following error.
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
If you want the values of unused and used you better call the script directly in the method that updated the UpdatePanel
string scriptData = "Plotly.newPlot('myDiv', { values: [" + used + ", " + unused + "], labels: ['Unused', 'Used '] });";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "startPlot", scriptData, true);
Or create a script that takes the values of used and unused and trigger the plot from there.
string scriptData = "setPlotValues(" + used + ", " + unused + ");";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "startPlot", scriptData, true);
Wen I finish (successfully) the new user registration I want to change the current page in a new notification page from my code behind.
For this purpose I use a javascript:
<script type="text/javascript">
var Tag;
function notifyscript(TagName) {
tag = TagName;
var myTag = document.getElementById(tag);
myTag.click();
}
in order to call:
<a id="notify" href="http://localhost/Pages/Account/Notification.aspx" target="_parent"/>
But it trow me an error when I run this locally.
500 (HTTP Error 500.0 - Internal Server Error
The call fails LoadLibraryEx στο φίλτρο ISAPI "C:\Windows\Microsoft.NET\Framework\v4.0.30319\\aspnet_filter.dll"
When I run this in the web doing nothing.
Is there someone who knows how to do this action?
I mean to open a new page when the code behind ends the registration.
Please try this code on Code Behind:
string url="www.google.com";
string msg = "<script type='text/javascript'>" +
" $(document).ready(function(){ " +
" window.location.href='" + url + "';" +
" });" +
"</script>";
page.ClientScript.RegisterStartupScript(page.GetType(), "myURL", msg);
I am attempting to access Google Books in order to an ISBN Code to get details of a book, I have a number of problem, which are:
A) I am trying to assemble a script request e.g. with the ISBN code concatenated into the URL. I have not managed to do this successfully - and I don't know why.
B) I then want to update a div in the DOM with this generated script dynamically, such that it will then execute.
C) I am finding it a bit of a puzzle as to the format of the returned data and the argument name of the function call contained in the Google response.
Has anyone else encountered the same problem and can offer guidance re A thru C above.
I enclose JavaScript code below.
$(document).ready(function() {
$('#viewbook-button').live('click', function() {
isbnCode = this.text;
alert("ISBN is : " + isbnCode + " " + this.text + " as well");
alert("Getting JSONP Google Books data");
isbnCode = "0451526538";
JSONPstr = '<' + 'script ' + 'src="' + 'https://www.googleapis.com/books/v1/volumes?q=ISBN' + isbnCode;
JSONPstr = JSONPstr + '&callback=handleJSONPResponse">' + '</script>';
alert("un-Escaped JSONP string" + JSONPstr);
escJSONPstr = escape( escJSONPstr );
alert("Escaped JSONP string");
//divstr = "";
//divstr = divstr + escape(<script src=");
//divstr = divstr + encodeURIComponent(https://www.googleapis.com/books/v1/volumes?q=ISBN);
//divstr = divstr + escape(isbnCode);
//divstr = divstr + encodeURIComponent(&callback=handleJSONPResponse);
//divstr = divstr + escape("></);
//divstr = divstr + escape(script);
//divstr = divstr + escape(>);
$('#jsonp-call').html(escJSONPstr);
// This will cause the handleJSONPResponse function to execute when the script is dynamically loadedinto div.
// The data wrapped in a function call will be returned from the Google Books server.
// This will cause the handleJSONPResponse function to execute below.
}); // end viewbook-button
}); // end document.ready
function handleJSONPResponse(response) {
var tmp = response;
alert(tmp);
};
</script>
</head>
<body>
<h2>Show Details of Books Ordered by a Customer</h2>
Get Customer Details
<br/><br/>
<div id="tablist">Tables will be Listed Here</div>
<br/><br/>
<div id="Google-call">The JSONP generated src= statement will go here and execute</div>
</body>
</html>
EDIT:
Problem solved - thanks everyone.
You're reinventing the wheel: jQuery has built-in JSONP support, so you don't need to faff about implementing it yourself. Use the $.ajax method:
$.ajax({
url: 'https://www.googleapis.com/books/v1/volumes?q=ISBN' + isbnCode,
dataType: 'jsonp',
success: function(response) {
console.log(response); // log the response object to the console
}
});
That should be all you need to do.
Okay, I've gotten a unique issue I've been trying to solve for two days.
I have System.Web.UI.WebControls.WebParts.WebPart control I am building a custom Sharepoint View with. Almost everything I want done is working except one little issue. I need to use Javascript to Format Date and Currency fields. The Client wants DateTime fields to be mm/dd/yyyy and currency have $ and commas where appropriate.
This is easy enough in javascript on a regular aspx page. I just wrote the functions and on page load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridFieldDAO dao = new GridFieldDAO();
myGrid.DataSource = dao.getItems();
myGrid.DataBind();
}
GetBuildFormattingScript();
}
private void GetBuildFormattingScript()
{
string script = "<script type=\"text/javascript\">";
script += " FormatByRows(\"" + myGrid.ClientID + "\",2);";
script += " FormatByRowsDate(\"" + myGrid.ClientID + "\",1);";
script += "</script>";
if(!ClientScript.IsClientScriptBlockRegistered("DoFormatting"))
ClientScript.RegisterStartupScript(typeof(string), "DoFormatting", script);
string script2 = " <script type=\"text/javascript\">"+
"var prm = Sys.WebForms.PageRequestManager.getInstance(); "+
"prm.add_beginRequest(BeginRequestHandler); "+
"prm.add_endRequest(EndRequestHandler); "+
"function BeginRequestHandler(sender, args) "+
"{ }"+
"function EndRequestHandler(sender, args) "+
"{ FormatByRows(\"" + myGrid.ClientID + "\",2); "+
" FormatByRowsDate(\""+myGrid.ClientID+"\",1);}</script> ";
if (!ClientScript.IsClientScriptBlockRegistered("DoUpdateFormatting"))
ClientScript.RegisterStartupScript(typeof(string), "DoUpdateFormatting", script2);
}
My issue in that on the OnLoad of the WebPart the grid I am wanting to update doesn't exists... so I have to add code to the OnPreRender.
Well, the WebPArt loads and the Javascript doesn't fire... so I click refresh and it does fire. Can anyone help me get the code working on the inital WebPart Load? Has anyone been able to get server side script to work this way in SharePoint?
Thanks,
Mike V
For this, you can take advantage of _spBodyOnLoadFunctionNames:
string script = "<script type=\"text/javascript\">";
script += " function FormatDataGridRows() {";
script += " FormatByRows(\"" + myGrid.ClientID + "\",2);";
script += " FormatByRowsDate(\"" + myGrid.ClientID + "\",1);";
script += " }";
script += " _spBodyOnLoadFunctionNames.push('FormatDataGridRows');";
script += "</script>";
Edit
To test, put the following code in a Content Editor web part on your page:
<script type="text/javascript">
function SayHello() {
alert('hello world!');
}
_spBodyOnLoadFunctionNames.push("SayHello");
</script>
I have a database at zoho creator. They feed me a json of the database content. I have trouble to parse and display that data with jquery or php or in html
Question : So how do I capture json data, and save (convert) it to file as XML. With the xml file I can parse it with jquery xpath easily... the "file" will be a local database, as a backup (if saved)
anybod have clue on that ?
as request.. here is the link for the query -link-
getting a way to display data from var i need is the minimum i must have !
like prod_categorie or prod_nom
note :
i can get help with any tutorial on
how to get xml data from zoho
any json to xml converter (jquery)
out there ?????
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
</head>
<body>
<div id="Liste_output"></div>
<script type="text/javascript">
jQuery.ajax({
url: "http://creatorexport.zoho.com/marcandremenard/application-lemieux/json/Liste_produits_View1/7GWhjVxYeNDePjPZnExCKy58Aqr21JX2hJEE6fAfgfkapEQnRjRd5RUy8wdjKuhmFEhJR9QRsBCUBjACAdSgmJNQSvxMt6geaMNC/",
dataType: "json",
success: function(data) {
var Liste_div = jQuery("#Liste_output");
var Liste_data = data["Liste_des_produits1"];
for (var i=0; i<Liste_data.length; ++i) {
var prod_i = Liste_data[i];
Liste_div.append('<div>' +
'<div>Nom: <span>' + prod_i["prod_nom"] + '</span></div>' +
'<img src="/images/prod/'+ prod_i["prod_photo"] +'"/>' +
'<div>Description: <span>' + prod_i["prod_desc"] + '</span></div>' +
'<div>Ingredient: <span>' + prod_i["prod_ingredient"] + '</span></div>' +
'<div>Odeur: <div class="odeur_cls"></div></div>' +
'<div>Certification: <div class="cert_cls"></div></div>' +
'</div>');
var odeur_data = prod_i["prod_odeur"];
for (var j=0; j<odeur_data.length; ++j) {
jQuery('#Liste_output odeur_cls').eq(j).append('<span>' +
odeur_data[j] + '</span>' + (j<odeur_data.length-1 ? ', ' : ''));
}
var cert_data = prod_i["prod_certification"];
for (var k=0; k<cert_data.length; ++k) {
jQuery('#Liste_output cert_cls').eq(k).append('<div>' + cert_data[k] + '</div>');
}
}
}
});
</script>
</body>
</html>
This will not work from a local file. The HTML must be served from the same domain as the database query, that is, it must be served from http://creatorexport.zoho.com (you can put it in the app subfolder)
– OR –
You must read the zoho docs and find out how to do a "callback" (sometimes called "JSONP"). Usually this is done by adding something like ?callback=data to the end of the URL.
Firstly, Javascript has no file-output capability. The best it can do is send data back to a server for processing there -- so the "capture json data, and save it to file as XML" idea is out.
What problems in particular are you having with using JSON? As it gets converted to a native Javascript object, I find it quite easy to work with myself. Though, I can see that if you wanted to use XPath to query it, JSON is no help. You should still be able to get to whatever data you need, but it might be a bit more verbose.
In your example JSON:
{"Liste_des_produits1":[{"Added_Time":"28-Sep-2009 16:35:03",
"prod_ingredient":"sgsdgds","prod_danger":["sans danger pour xyz"],"prod_odeur"..
You could access the prod_danger property like this:
$.getJSON(url, function(data) {
var danger = data.List_des_produits1[0].prod_danger;
});
If you are having trouble getting the right path to a property, Firebug is a great help with this. Just call this:
$.getJSON(url, function(data) {
console.log(data);
});
...and then you can browse through its properties in a tree-structure.
There are jQuery pluggins for such convertion, for example json2xml.