I am trying to create DataSourceRequest without actually running on ASP.NET MVC.
If I were on MVC, I could use:
public ActionResult GetResults([DataSourceRequest]DataSourceRequest request)
{
...
But, I cannot use MVC (reasons, you know...) so what I am looking for is something like AmazingParsingKendoLibrary.ParseFromQueryString() which will return DataSourceRequest
Is there any support for programmatic parsing like this?
This method works as I use it to replicate the grid when doing a custom file export:
setRequestObject: function () {
var grid = $("#YOUR_GRID_ID").data("kendoGrid");
this.requestObject = (new kendo.data.transports["aspnetmvc-server"]({ prefix: "" }))
.options.parameterMap({
page: grid.dataSource.page(),
sort: grid.dataSource.sort(),
filter: grid.dataSource.filter()
});
var pageArg = "page=" + (this.requestObject.page || '~');
var sortArg = "sort=" + (this.requestObject.sort || '~');
var psizeArg = "pageSize=" + grid.dataSource._pageSize;
var filterArg = "filter=" + (this.requestObject.filter || '~');
this.exportFileUrl = pageArg + "&" + sortArg + "&" + psizeArg + "&" + filterArg;
},
I hope this helps. Good luck
Related
I use mimekit to send e-mail. But in e-mail design there is a {} in css codes and I need to use a structure like {0}, {1} etc to print data with mimekit, and this structure is complicated by css {0} index, {{0} How to change it.
My Code;
var pathToFile = _enviorment.WebRootPath
+ Path.DirectorySeparatorChar.ToString()
+ "Templates"
+ Path.DirectorySeparatorChar.ToString()
+ "EmailTemplate"
+ Path.DirectorySeparatorChar.ToString()
+ "Discount.html";
var builder = new BodyBuilder();
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
{
builder.HtmlBody = SourceReader.ReadToEnd();
}
var messageBody = string.Format(builder.HtmlBody,
_strName,
_strSurname,
_discountCode
);
Error Message;
FormatException: Input string was not in a correct format.
I'm trying to search notes by the attribute sourceURL but it seems API is stripping away the protocol and the result is no results. Here is the code
var notesTransport = new Thrift.Transport(
Eventnote.Auth.oauth.getParameter(Eventnote.Auth.note_store_url_param));
var notesProtocol = new Thrift.Protocol(notesTransport);
var noteStore = new NoteStoreClient(notesProtocol, notesProtocol);
if (!noteStore) {
Eventnote.Logger.error("[EVERDU] Connection failure during getting note store");
return;
}
var filter = new NoteFilter();
filter.words = "sourceURL:" + url + "*";
try {
var results = noteStore.findNotes(Eventnote.Auth.get_auth_token(), filter,
0, 100);
...
The reasults objects looks like this
{
"startIndex":0,
"totalNotes":0,
"notes":[
],
"stoppedWords":null,
"searchedWords":[
"//github.com/sameersbn/docker-gitlab*"
],
"updateCount":18461
}
Is there something I am missing?
Not sure if that counts as a bug on Evernote's end or not, butyou can add double quotes around your url to make it work.
filter.words = "sourceURL:\"" + url + "*\"";
I'm writing a report in ASP.NET using Reporting Services. I want to hide the Toolbar of the ReportViewer and have my own "Next Page" and "Previous Page" buttons. Is there a way to programmatically navigate through ReportViewer pages? Does it have methods such as "NextPage" and "PreviousPage"?
If you hide the toolbar and have your own controls for page navigation you could set the ReportViewer's CurrentPage property in your code.
I just thought I'd add to this as I've been doing similar things and have built a little set of JavaScript (using JQuery) functions where you can pass the ReportViewerID and it'll allow you to add next, previous, first last and so on to your own custom toolbar buttons. Just hide the toolbar using the ReportViewer_HideToolbar function on document ready. Thought it was worth sharing as I couldn't find anything on this when searching for hours yesterday. Even if it's just a starting point for someone, atleast it's that bit closer and of help :-)
p.s. I'm using ReportViewer 10, others may be different and not work.
function ReportViewer_FirstPage(ReportViewerID) {
var ReportViewer = $("span[id$='" + ReportViewerID + "_ReportViewer'")
ReportViewer.find("input[title='First Page']").first().click()
}
function ReportViewer_NextPage(ReportViewerID) {
var ReportViewer = $("span[id$='" + ReportViewerID + "_ReportViewer'")
ReportViewer.find("input[title='Next Page']").first().click()
}
function ReportViewer_PreviousPage(ReportViewerID) {
var ReportViewer = $("span[id$='" + ReportViewerID + "_ReportViewer'")
ReportViewer.find("input[title='Previous Page']").first().click()
}
function ReportViewer_LastPage(ReportViewerID) {
var ReportViewer = $("span[id$='" + ReportViewerID + "_ReportViewer'")
ReportViewer.find("input[title='Last Page']").first().click()
}
var tReportViewerLastFindText = ""
function ReportViewer_Set_SearchText(ReportViewerID, tText) {
var ReportViewer = $("div[id$='MainPlaceHolder_" + ReportViewerID + "'")
ReportViewer.find("input[title='Find Text in Report']").val(tText)
var m_reportViewer = $find($(ReportViewer).attr('id'))
if (tReportViewerLastFindText != tText) {
m_reportViewer.find(tText)
tReportViewerLastFindText = tText
} else {
m_reportViewer.findNext()
}
}
function ReportViewer_Set_PageNumber(ReportViewerID, tPageNumber) {
var ReportViewer = $("span[id$='" + ReportViewerID + "_ReportViewer'")
var CurrentPage = ReportViewer.find("input[title='Current Page']")
$(CurrentPage).val(tPageNumber)
__doPostBack(CurrentPage.attr("name"), '')
}
function ReportViewer_Print(ReportViewerID) {
var ReportViewer = $("div[id$='MainPlaceHolder_" + ReportViewerID + "'")
var m_reportViewer = $find($(ReportViewer).attr('id'))
m_reportViewer.invokePrintDialog()
}
function ReportViewer_HideToolbar(ReportViewerID) {
var ReportViewer = $("span[id$='" + ReportViewerID + "_ReportViewer'")
$(ReportViewer).find("div[style$='toolbar_bk.png);']").hide()
}
Regards
Liam
I am using calender control in asp.net 2.0, and after clicking on button its opening in another form. I am using the following JS code to open the window:
function openwindow(txtvalueID) {
leftVal = (3500 - screen.width) / 2;
topVal = (800 - screen.height) / 2;
if (txtvalueID == 'ctl00$CPH1$txtHireDate') {
var txtid = '<%=txtHireDate.ClientID %>';
}
else {
var txtid = '<%=txtTermDate.ClientID %>';
}
var frmid = '<%=Page.Form.ClientID %>';
var qs = "formname=" + frmid + "." + txtid;
window.open('/Calender.aspx?' + qs, 'calendar_window', 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=230,height=240,left=' + leftVal + ',top=' + topVal + ',screenX=400,screenY=400')
}
function isNumeric(keyCode) {
return ((keyCode >= 48 && keyCode <= 57) || keyCode == 8)
}
In this line txtvalueID == 'ctl00$CPH1$txtHireDate' is wrong. I am referring to the control id, but the control id keeps changing.. Why?
You shouldn't explicitly refer to the ID directly, but instead do:
if (txtvalueID == '<%=txtHireDate.ClientID %>') {
In the first if line, that will help with the ID changing issue.
HTH.
How do I create an ASP.NET web service that returns JSON formatted data?
The most important thing to understand is to know how to represent data in JSON format.
Please refer http://www.json.org/ to know more about it.
Once you understand this, then the rest part is pretty straight forward.
Please check the following URL for an example of the same.
http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=264
http://code.msdn.microsoft.com/JSONSampleDotNet
http://www.phdcc.com/xml2json.htm
I recommend Jquery library for this. It's a lightweight rich library which supports calling web services, handle json data format output etc.
Refer www.jquery.com for more info.
.NET 3.5 has support built-in. For .NET 2.0, extra libraries are needed. I used the Jayrock library.
I recently delivered an application that uses pure Javascript at the browser (viz. using AJAX technology, but not using Microsoft AJAX or Scriptaculous etc) which marries up to Microsoft webservices at the back end. When I started writing this I was new to the world of .NET, and felt overwhelmed by all the frameworks out there! So I had an urge to use a collection of small libraries rather than very large frameworks.
At the javascript application, I call a web service like this. It directly reads the output of the web service, cuts away the non JSON sections, then uses https://github.com/douglascrockford/JSON-js/blob/master/json2.js to parse the JSON object.
This is not a standard approach, but is quite simple to understand, and may be of value to you, either to use or just to learn about webservices and JSON.
// enclosing html page has loaded this:
<script type="text/javascript" src="res/js/json2.js"></script>
// Invoke like this:
// var validObj = = callAnyWebservice("WebServiceName", "");
// if (!validObj || validObj.returnCode != 0) {
// alert("Document number " + DocId + " is not in the vPage database. Cannot continue.");
// DocId = null;
// }
function callAnyWebservice(webserviceName, params) {
var base = document.location.href;
if (base.indexOf(globals.testingIPaddr) < 0) return;
gDocPagesObject=null;
var http = new XMLHttpRequest();
var url = "http://mywebserver/appdir/WebServices.asmx/" + webserviceName;
//alert(url + " " + params);
http.open("POST", url, false);
http.setRequestHeader("Host", globals.testingIPaddr);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.setRequestHeader("Content-Length", params.length);
// http.setRequestHeader("Connection", "close");
//Call a function when the state changes.
http.onreadystatechange = function() {
if (http.readyState == 4 ) {
if (http.status == 200) {
var JSON_text = http.responseText;
var firstCurlyQuote = JSON_text.indexOf('{');
JSON_text = JSON_text.substr(firstCurlyQuote);
var lastCurlyQuote = JSON_text.lastIndexOf('}') + 1;
JSON_text = JSON_text.substr(0, lastCurlyQuote);
if (JSON_text!="")
{
//if (DEBUG)
// alert(url+" " +JSON_text);
gDocPagesObject = eval("(" + JSON_text + ")");
}
}
else if (http.readyState == 4)
{alert(http.readyState + " " + http.status + " " + http.responseText)}
}
}
http.send(params);
if (gDocPagesObject != null) {
//alert(gDocPagesObject.returnCode + " " + gDocPagesObject.returnString);
return gDocPagesObject;
}
else
return "web service unavailable: data not ready";
}
In our project the requirements were as follow -- ASP.NET 2.0 on the server, and pure Javascript on the browser (no JQuery libs, or .NET AJAX)
In that case on the server side, just mark the webmethod to use JSON. Note that both input and output params are json formatted
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public String Foo(String p1, String p2)
{
return "Result: p1= " + p1 + " p2= " + p2;
}
On the javascript side, use the regular XmlHttpRequest object, make sure you format your input params as JSON and do an 'eval' on output parms.
var httpobj = getXmlHttpRequestObject();
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject()
{
if (window.XMLHttpRequest)
return new XMLHttpRequest();
else if(window.ActiveXObject)
return new ActiveXObject("Microsoft.XMLHTTP");
}
CallService()
{
//Set the JSON formatted input params
var param = "{'p1' : 'value1', 'p2' : 'value2'}";
//Send it to webservice
if(httpobj.readyState == 4 || httpobj.readyState == 0)
{
httpobj.open("POST", 'service.asmx/' + 'Foo', true);
//Mark the request as JSON and UTF-8
httpobj.setRequestHeader('Content-Type','application/json; charset=utf-8');
httpobj.onreadystatechange = OnSuccess;
httpobj.send(param);
}
}
OnSuccess()
{
if (httpobj.readyState == 4)
{
//Retrieve the JSON return param
var response = eval("(" + httpobj.responseText + ")");
}
}