|
Your welcome
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
There is a physical html file and I need to traverse through all the html elements in an html file.
And the constraint is I can't use any third party components like HtmlAgilityPack or SuperStarHtml.
I think the best way is to preparing a XmlDocument from the html. But it is erroring out if the html contains any characters like .
Anyone having any idea to resolve this please share with me.
Thanks in advance.
|
|
|
|
|
HTML is not XML; you can't use an XML parser to load HTML.
Why can't you use a third-party component? Writing your own version of HtmlAgilityPack seems like a lot of work to satisfy a "Not Invented Here" philosophy.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have developed a custom Comment Control using class library file
now i want to use the dll of this file in web application which is developing on MVC Framework
so what are the ways of adding and using this dll in this project
|
|
|
|
|
Are you having trouble with the normal ways? You know, adding the DLL directly as a reference, or adding your whole project and referencing the project?
|
|
|
|
|
I have added dll file in project reference, bin folder as well as bin_deployableAssemblies
now i want use this control in .cshtml file
how can i write syntax for use this control in this file
|
|
|
|
|
It would have been nice if you could have said that at the beginning. I haven't ever done that myself, but ten seconds on Google did find this article, which looks to be what you're trying to do.
Custom Controls in MVC[^]
WHY were you not able to find that on Google? Or did you read it and need help with it?
|
|
|
|
|
i had serach on google but i was not found anything that what i want
i hav done custom control(generic) in asp.net
and i want implement it in web application which has in MVC framework.
|
|
|
|
|
The article I posted should get you there. It is about MVC, like it says. I don't think it's standard procedure to use server controls in MVC, but it's possible to do if you want.
|
|
|
|
|
OK, I'm at my wit's end with this sucker! I basically think I have two options, and both options are doing something screwed up and I can't explain why, but would really just rather have it stop! I'm trying to integrate a KendoUI Grid control, and an ASMX page method. I got the "Read" method to work great - it did take some work to get the JSON running back and forth properly, but it works really nicely. Now, I'm trying to do the "Update" and "Create" methods. The problem is my grid isn't sending back the proper data format. It's sending the right data, but the encoding is screwed up in many different ways depending on how I do it.
Here's my JQuery code at the moment...
function getJson(input) {
var k = JSON.stringify(input);
return k;
}
$(document).ready(function () {
$("#PeopleGrid").kendoGrid({
columns: ["LastName", "FirstName", "Phone"],
dataSource: {
transport: {
read: {
type: "POST",
url: "TestKendoGrid.aspx/Read",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
create: {
type: "POST",
url: "TestKendoGrid.aspx/Create",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
update: {
type: "POST",
url: "TestKendoGrid.aspx/Update",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: function (x) { return getJson(x); }
}
},
schema: {
data: "d",
columns: ["ID", "LastName", "FirstName", "Phone"],
model: {
id: "ID",
fields: {
LastName: {
editable: true,
nullable: false
},
FirstName: {
editable: true,
nullable: false
},
Phone: {
editable: true,
nullable: false
}
}
}
},
batch: false
},
editable: {
update: true,
create: true,
destroy: false
},
toolbar: ["create", "save", "cancel"]
})
});
The little function at the top is just so I can see the values in the debugger. With the current code, "input" is the actual object I'm trying to send back and "k" actually IS the exact JSON string I want to POST back to my server. Problem is, when I look at what was actually sent, it's funky as hell! This is what the request looks like...
POST http://localhost:54346/TestKendoGrid.aspx/Update HTTP/1.1
Host: localhost:54346
Connection: keep-alive
Content-Length: 1930
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost:54346
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31
Content-Type: application/json; charset=UTF-8
Referer: http://localhost:54346/TestKendoGrid.aspx
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP.NET_SessionId=dkmbybyaz0bitvat2wbdueti
0=%7B&1=%22&2=_&3=_&4=t&5=y&6=p&7=e&8=%22&9=%3A&10=%22&11=T&12=e&13=s
&14=t&15=W&16=e&17=b&18=S&19=i&20=t&21=e&22=.&23=P&24=e&25=r&26=s&27=o
&28=n&29=%22&30=%2C&31=%22&32=I&33=D&34=%22&35=%3A&36=5&37=%2C&38=%22&39=L
&40=a&41=s&42=t&43=N&44=a&45=m&46=e&47=%22&48=%3A&49=%22&50=A&51=d&52=a
&53=m&54=s&55=o&56=n&57=%22&58=%2C&59=%22&60=F&61=i&62=r&63=s&64=t&65=N
&66=a&67=m&68=e&69=%22&70=%3A&71=%22&72=D&73=a&74=n&75=i&76=e&77=l&78=l
&79=e&80=%22&81=%2C&82=%22&83=P&84=h&85=o&86=n&87=e&88=%22&89=%3A&90=%22
&91=3&92=0&93=3&94=-&95=5&96=2&97=3&98=-&99=8&100=7&101=1&102=9&103=%22
&104=%2C&105=%22&106=E&107=n&108=t&109=i
&110=t&111=y&112=S&113=t&114=a&115=t&116=e&117=%22&118=%3A&119=2&120=%2C
&121=%22&122=E&123=n&124=t&125=i&126=t&127=y&128=K&129=e&130=y&131=%22&132=%3A
&133=%7B&134=%22&135=E&136=n&137=t&138=i&139=t&140=y&141=S&142=e&143=t&144=N
&145=a&146=m&147=e&148=%22&149=%3A&150=%22&151=P&152=e&153=o&154=p&155=l
&156=e&157=%22&158=%2C&159=%22&160=E&161=n&162=t&163=i&164=t&165=y&166=C
&167=o&168=n&169=t&170=a&171=i&172=n&173=e&174=r&175=N&176=a&177=m&178=e
&179=%22&180=%3A&181=%22&182=S&183=a&184=n&185=d&186=b&187=o&188=x&189=E&190=n
&191=t&192=i&193=t&194=i&195=e&196=s&197=%22&198=%2C&199=%22&200=E&201=n&202=t
&203=i&204=t&205=y&206=K&207=e&208=y&209=V&210=a&211=l&212=u&213=e&214=s
&215=%22&216=%3A&217=%5B&218=%7B&219=%22&220=K&221=e&222=y&223=%22&224=%3A&225=%22
&226=I&227=D&228=%22&229=%2C&230=%22&231=V&232=a&233=l&234=u&235=e&236=%22
&237=%3A&238=5&239=%7D&240=%5D&241=%2C&242=%22&243=I&244=s&245=T&246=e&247=m&248=p
&249=o&250=r&251=a&252=r&253=y&254=%22&255=%3A&256=f&257=a&258=l&259=s&260=e
&261=%7D&262=%7D&__type=TestWebSite.Person&ID=5&LastName=Adamson&FirstName=Danielle&Phone=303-555-1212&EntityState=2&EntityKey%5BEntitySetName%5D=People&EntityKey%5BEntityContainerName%5D=SandboxEntities
&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BKey%5D=ID&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BValue%5D=5&EntityKey%5BIsTemporary%5D=false
LOL, wut?! It's encoding each character as if it's a separate parameter! What in the hell?!
If I don't "stringify" it posts the data as URL-encoded, like this:
POST http://localhost:54346/TestKendoGrid.aspx/Update HTTP/1.1
Host: localhost:54346
Connection: keep-alive
Content-Length: 320
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost:54346
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31
Content-Type: application/json; charset=UTF-8
Referer: http://localhost:54346/TestKendoGrid.aspx
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP.NET_SessionId=dkmbybyaz0bitvat2wbdueti
__type=TestWebSite.Person&ID=18&LastName=Russell&FirstName=Graham&Phone=303-555-5000&EntityState=2&EntityKey%5BEntitySetName%5D=People&EntityKey%5BEntityContainerName%5D=SandboxEntities
&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BKey%5D=ID&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BValue%5D=18&EntityKey%5BIsTemporary%5D=false
And of course, ASP.Net responds to that with a 500 error of "Invalid JSON Primitive" which basically means it choked, according to http://encosia.com/asmx-scriptservice-mistake-invalid-json-primitive/[^]
So, I'm trying to follow the advice in the article, but that's causing the really weird request in the first snippet. So, I'm not sure what to do!
It should be posting this (the value of "k" in the little function):
{"__type":"TestWebSite.Person","ID":5,"LastName":"Adamson","FirstName":"Danielle","Phone":"303-555-1212","EntityState":2,"EntityKey":{"EntitySetName":"People","EntityContainerName":"SandboxEntities","EntityKeyValues":[{"Key":"ID","Value":5}],"IsTemporary":false}}
My WebMethod on the receiving side is here - the Read method works great, but the other two haven't even seen a proper request so I'm not sure if they are correct yet.
[WebMethod]
public static List<Person> Read() {
using (SandboxEntities entity = new SandboxEntities()) {
var q = from p in entity.People
select p;
return q.ToList<Person>();
}
}
[WebMethod]
public static void Create(Person pIn) {
using (SandboxEntities e = new SandboxEntities()) {
e.AddToPeople(pIn);
e.SaveChanges();
}
}
[WebMethod]
public static void Update(Person pIn) {
using (SandboxEntities e = new SandboxEntities()) {
Person pUpdate = (Person)(from p in e.People where p.ID == pIn.ID select p).First();
pUpdate.Phone = pIn.Phone;
pUpdate.FirstName = pIn.FirstName;
pUpdate.LastName = pIn.LastName;
e.SaveChanges();
}
}
I've dug myself a big hole here, please help me get out! TIA
modified 1-Apr-13 19:19pm.
|
|
|
|
|
|
Thanks! I did get it figured out. Something to do with the ParameterMap function. I added a basic stringify into that, and now it sends back the proper JSON in the POST request.
However, now I'm getting some kind of type conversion problem. The incoming object IS being parsed correctly into a Person object, but then the framework is trying to convert it into a Dictionary object, which fails and throws an exception and a 500 back to the browser. I have no additional information than that, so it's a pretty big mystery at the moment.
I think this question is maybe too advanced for this forum. I know there's smart people here like you and me, and I thought this question was interesting enough to attract those folks, but I'm stumped so maybe everybody else is too? If you looked at this question and tried to solve it, please let me know what you found! We might work it out together.
This is the Javascript right now - this sends the proper JSON back to the server (and the server even deserializes it correctly to a Person object, then it chokes trying to do something unnecessary).
$(document).ready(function () {
$("#PeopleGrid").kendoGrid({
columns: ["LastName", "FirstName", "Phone"],
dataSource: {
transport: {
read: {
type: "POST",
url: "TestKendoGrid.aspx/Read",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
create: {
type: "POST",
url: "TestKendoGrid.aspx/Create",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
update: {
type: "POST",
url: "TestKendoGrid.aspx/Update",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
parameterMap: function (data, type) {
return kendo.stringify(data);
}
},
schema: {
data: "d",
columns: ["ID", "LastName", "FirstName", "Phone"],
model: {
id: "ID",
fields: {
LastName: {
editable: true,
nullable: false
},
FirstName: {
editable: true,
nullable: false
},
Phone: {
editable: true,
nullable: false
}
}
}
},
batch: false
},
editable: {
update: true,
create: true,
destroy: false
},
toolbar: ["create", "save", "cancel"]
})
});
|
|
|
|
|
|
It's failing on the server side, but before it gets to my function. It's failing somewhere in the .Net Framework code, because it's trying to turn the Person object into a Dictionary, which is not a conversion that can be done. What I don't understand is why it's trying to do that, when it has a Person object it could pass directly to my function. Something isn't right in the wiring and I don't know what. I'll take a look at the article you posted and see what it's about, but I think I've read it before.
|
|
|
|
|
|
BTW, this is the error I'm getting (returned to my page in perfect JSON)
{
"Message": "Cannot convert object of type \u0027TestWebSite.Person\u0027 to type \u0027System.Collections.Generic.IDictionary`2[System.String,System.Object]\u0027",
"StackTrace": " at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)
at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)
at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)
at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)",
"ExceptionType": "System.InvalidOperationException"
}
What is totally stupid about this is, I can debug in the ObjectConverter.ConvertObjectToTypeMain function, and when I inspect the parameter "o" - it is of type "Person" which is exactly what my WebMethod needs. I do not understand why it's trying to convert it to something else at that point.
|
|
|
|
|
I've come to the conclusion that KendoGrid is an advanced Jquery Object sort of like CKEditor, and that it has an code interface that is the go between the UI Object, and backend support for creating, updating and deleting records via a web service.
Let's take the Web Service first. I suspect that it should be registered on a asmx page, and not aspx page. I don't know if that is your mistake or the way it was packaged from Kendo Dojo as an example.
TestKendoGrid.asmx/Update
The following web method takes a non-primitive value. So instead of person being an integer or string, it's an object called person, that must be described somewhere on that page, or somewhere in the project.
Person pIn is the non-primitive. Once again, I don't if you wrote this, or if it was provided as a live example, but in order to consume person, it must be pre-consumed first and then consumed, and the object elements must be described somewhere in the web method or a seperate class.
So Update returns nothing, no exit code or anything. Only List returns data back as an object called person, and not a JSON String. That why you can't stringify the object. There must be something in the KendoGrid file that parses the Person Object, and updates the KendoGrid.
From what I can tell, People is an array or a table, collection, and person is a single record in People.
[WebMethod]
public static void Update(Person pIn) {
using (SandboxEntities e = new SandboxEntities()) {
Person pUpdate = (Person)(from p in e.People where p.ID == pIn.ID select p).First();
pUpdate.Phone = pIn.Phone;
pUpdate.FirstName = pIn.FirstName;
pUpdate.LastName = pIn.LastName;
e.SaveChanges();
}
}
In my opinion, this is a custom program or solution, made to be easy to use and customized, and that you need to get the example code working first, before making any changes. The Kendo DoJo must have a forum or help source that you can get a better answer from than here.
I'm not going to dive into downloading the demo, and setting up a complete project to figure this one out.
I deleted my other posts, because they are not relevant to this subject, just misleading for those that follow.
Let me know if this is pure demo code, or if you started writing code from scratch to support the Kendo Grid. If it's pure demo code, then you missing a file for person and people.
|
|
|
|
|
Oh heck no, this is way beyond the demo code. I've already got the demos working and played with those quite a bit. This is actually just a simple example seeing if I can use the Entity Framework on the back end. We have a considerable project that we are testing the Kendo controls for. So, I wanted to try something simple first. I made a DB-first Entity Framework class for a simple table back in the database. Then I just used what I know about JQuery AJAX and the various blogs I could find, and did this up from scratch. The problem is, since we're not sure we are using Kendo or not, we don't have a license and can't use their 'special' forums, I can only post on here or StackOverflow and stuff. There's a few other ASP.Net developers at my company, but they aren't familiar with the newer stuff like using JQuery and ASP together, or MVC/Razor pages and Entity Framework. So, I'm kinda on my own.
I really appreciate you taking the time to think about this for me. I think you've given me some very good ideas to try. I'll just have to give it a go when I get back to the office. I'll let you know how it goes. The ASMX suggestion is a good one - the blog I posted says ASPX page methods work with JQuery AJAX, but it's worth a try on the other method. FYI, the method at the top that returns a List - that does return JSON, as the blog says it can.
Anyway thanks again for looking at this, I hope I can help you in the future
And, your other messages were helpful, you should have left them. Anything that gives me something to think about in a different way moves me forward.
|
|
|
|
|
OK!
That clarifies things for me. I guess like Richard Says, The first guest is the best guess, and I was on the right track after all. So I deleted messages containing actual help, but after looking at the Kendo Project, I had to back up and question who wrote or modified something that was working.
The following JSON, is it going in, or being returned?
{
"__type": "TestWebSite.Person",
"ID": 5,
"LastName": "Adamson",
"FirstName": "Danielle",
"Phone": "303-555-1212",
"EntityState": 2,
"EntityKey": {
"EntitySetName": "People",
"EntityContainerName": "SandboxEntities",
"EntityKeyValues": [
{
"Key": "ID",
"Value": 5
}
],
"IsTemporary": false
}
}
You should post the header to the web service, and the 3 web services, can't tell if you have the required attributes needed for Jquery.
|
|
|
|
|
LOL, ok... this is a lot of fun...
The Create method, which I hadn't tried, works fine! I had to wrap my object in a variable name as mentioned in the article you posted, but it works. The Javascript looks like this now...
var svcURL = "SandboxService.asmx";
$(document).ready(function () {
$("#PeopleGrid").kendoGrid({
columns: ["LastName", "FirstName", "Phone"],
dataSource: {
transport: {
read: {
type: "POST",
url: svcURL + "/Read",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
create: {
type: "POST",
url: svcURL + "/Create",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: function (data) { return { P: data }; }
},
update: {
type: "POST",
url: svcURL + "/Update",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: function (data) { return { P: data }; }
},
parameterMap: function (data, type) {
return kendo.stringify(data);
}
},
schema: {
data: "d",
columns: ["ID", "LastName", "FirstName", "Phone"],
model: {
id: "ID",
fields: {
LastName: {
editable: true,
nullable: false
},
FirstName: {
editable: true,
nullable: false
},
Phone: {
editable: true,
nullable: false
}
}
}
},
batch: false
},
editable: {
update: true,
create: true,
destroy: false
},
toolbar: ["create", "save", "cancel"]
})
});
I did change to ASMX, but the methods basically look the same... Update is still throwing the "Can't convert" error, but Create is not having that problem.
using System.Web.Services;
using System.Web.Script.Services;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
namespace TestWebSite {
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class SandboxService : System.Web.Services.WebService {
[WebMethod]
public List<Person> Read() {
using (SandboxEntities entity = new SandboxEntities()) {
var q = from p in entity.People select p;
return q.ToList<Person>();
}
}
[WebMethod]
public void Create(object P) {
if (P is Person) {
using (SandboxEntities e = new SandboxEntities()) {
e.AddToPeople((Person)P);
e.SaveChanges();
}
}
}
[WebMethod]
public void Update(object P) {
if (P is Person) {
using (SandboxEntities e = new SandboxEntities()) {
Person pUpdate = (Person)(from p in e.People where p.ID == ((Person)P).ID select p).First();
pUpdate.Phone = ((Person)P).Phone;
pUpdate.FirstName = ((Person)P).FirstName;
pUpdate.LastName = ((Person)P).LastName;
e.SaveChanges();
}
}
}
}
}
Freekin weird if you ask me... I hate it when there's no explanation why two identical things behave differently.
|
|
|
|
|
Yah, your consuming the object P now, you should be able to walk through the code by loading the web service class file, or file, and set a break-point on update, to see if the using entity code is throwing an exception.
But I'm sure you thought of that already.
Indian123 was working with the entity framework and web services about 6 months ago, haven't seen him around for awhile now.
I downloaded the demo, and I can you have a ton of time in this beyond what they ship. I'm not running anything capable of HTML 5 right now, till I upgrade.
|
|
|
|
|
Thanks again for all your help! I kinda got it to work. It's working with a Dictionary though, which isn't going to work long term, but at least it's not a total loss. I don't know if we'll use this method knowing that I'll have to write a lot of custom code for each table. We were hoping to just generate a lot of code, and if we can't do that, it isn't very much value to change from what we're doing now. The Kendo Grid is a little more interactive, but if the overhead to get that is "write custom classes in javascript for every object" then it defeats the purpose of using the EF stuff, kinda. We did decide to pay for the license though, mainly for the support. I've spent more time on this already, than what the license costs.
|
|
|
|
|
I'm pretty conservative now days with using 3rd party stuff. I've wasted too much much time in my life trying to make things work, like that Javascript from a customer project that was a total joke, a wordpress plugin that didn't work as expected, so I rewrote it from scratch and posted it as a tip/trick.
I looked at the Kendo demo, it looks nice, pretty, but I could of wrote my own from scratch in a in a week, that would do what I need it to do, and easy to understand and support.
Let somebody younger figure it out and preserve your work.
|
|
|
|
|
Yeah I know what you mean, but sometimes that stuff can really help keep you on schedule too. I've had great luck with things like DotNetNuke and Joomla, and most JQuery stuff works like it should. But you are right, I could have met the requirements with Webforms or MVC last week. I will figure it out eventually. If I had a blog I might write it up, but I never seem to have time for that stuff.
|
|
|
|
|
Well you ahead of the curve on me, I haven't tried MVC yet, I'm old an I remember Microsoft saying VB will no longer be supported, oh back in 99. So I'm skeptical on tech stuff from Microsoft.
late here, need to go home and watch the Americans.
I think I remember you posting some questions last year, or knocking out some answers.
|
|
|
|
|