ajax auto complete extender results as strings - c#

i have run into an interesting issue...
i am using ASP and auto-complete extender on a textbox
i got everything working but i was getting very odd results.
when searching for something like 315122-111 the only result that would come up was 315011.
this is because the item-number is being treated like a number instead of a string
315122-111=315011
i am sending everything as a string.. when i use fiddler to view the traffic all the auto-complete responses coming in 315122-111 they are just not being properly...
any ideas on how to fix this dilemma?

Is there an eval() being called on the javascript side?
http://www.w3schools.com/jsref/jsref_eval.asp
There's a bug that was fixed in this post:
http://forums.asp.net/t/1164200.aspx?New+AutoCompleteExtender+doesn+t+work+with+Numeric+Values
They stated:
1. download the ajax control toolkit source. open the file
2. AjaxControlToolkit\AutoComplete\AutoCompleteBehavior.js at line 748,
3. you should see: "if (String.isInstanceOfType(pair)) {"
That line is what is causing the problem.... to fix it, I changed that line to "if (String.isInstanceOfType(pair) || Int.isInstanceOfType(pair)) {".

Related

Trying to get word count using HtmlAgilityPack, but node list is returning as null

I have the following code that grabs the nodes with text for certain descendants of specific tags/classes, and it was working before, but I haven't ran this program in a couple of months (nobody else has touched it) so I'm wondering why it's throwing an error now. My nodeList looks like this:
var nodesList = doc.DocumentNode
.SelectNodes("//article[#class='article-content']//div[#class='article-content-block']//text()[not(parent::script)]")
.Select(node => node.InnerText).ToList();
I look at the web page, and there are multiple paragraph and ul tags that fit that particular Xpath query, but nodesList is returning:
System.ArgumentNullException: 'Value cannot be null. (Parameter 'source')'
The DocumentNode has name: #document, which I would expect is normal and the InnerHtml is showing the entirety of the page's HTML however the InnerText is showing Javascript must be enabled for the correct page display. Any ideas as to why it would be throwing null? I don't recall seeing the Javascript must be enabled for the correct page display before for the DocumentNode's InnerText, so I'm wondering if that has something to do with it.
It sounds like the webpage content is being loaded dynamically. That's not a problem for your browser, because it executes Javascript automatically, but the .NET web components don't do any of that. You should be able to use your browser's dev tools to determine which request actually contains the content you're looking for, and then replicate that request in your code.
It could also be that something else about your request isn't playing nice with the server - missing/bad HTTP headers, unexpected TLS version, maybe even firewall stuff - causing it to return a different response.

Plus sign converts to + in nopcommerce 41 but resolve into 42beta

My website is build with nopcommerce41. '+' characters are being replaced with &#x2B on runtime.
Everything is working fine except for this issue.
Example: Google search results displays url look like www.demo.com?search=+apple but bing search engine display this same url look like www.demo.com?search=+apple.
If user comes from bing search engine then user can't find expected result.
now I have compared the code of both versions of nopcommerce41 and nopcommerce42beta and result is as shown below:
view-source:http://nop42beta-001-site1.ftempurl.com/ (this site into 4.2beta)
e.g. <li class=facebook><a href=//www.facebook.com/+nopCommerce target=_blank>Facebook</a>
view-source:http://demo.nopcommerce.com/ (this site into 4.1)
e.g. Google+
nopcommerce team already fixed this issue into nopcommrce 4.2beta but I dont want to upgrade my project. Can any one help me solve this issue?
This issue already reported into development section but this is a problematic bug so I have posted here.
https://www.nopcommerce.com/boards/t/62489/plus-sign-converts-to-x2b-in-nopcommerce-versions-running-on-net-core.aspx
one example to understand this issue
one more example as below:-
In a Index.chtml file i have write code
#{
Layout = null;
var test1 = "/+apple";
}
Sangeet1
Sangeet2
now i have run project then i got result as below
view-source:http://localhost:15543/
Sangeet1
Sangeet2
second dynamic string + symbol convert into +(Unicode Hex Character Code) but first static value not converted.
nocommerce is open source, you can find the changeset that fixes your issue and build a 4.1 version with this specific fix

How do I write a text file from within a C# ASP.NET page?

I'm coming to C# ASP.NET from Ruby and PHP, and I'm enjoying some elements of it but am finding certain things difficult to achieve. It's a bit different to get my head around, and I'd really appreciate it if someone could help me get this bit up and running.
I am trying to take some text sent in a POST request, HTML-escape it, and then write it to a text file.
So I look it up, read a little, and try:
<%
System.IO.StreamWriter file = new System.IO.StreamWriter(Server.MapPath(#"./messager.txt"));
file.WriteLine(Request.Form["message"]);
file.Close();
%>
Not doing the HTML-escaping yet, just trying to actually write to the text file.
This doesn't work, though; it throws no error that I can see, but just does nothing, the text file isn't written to at all. I've researched the methods and can't really figure out why. I would really love some help.
If it helps, here is working Ruby code for what I am trying to do:
File.open "messager.txt", "w" {|f| f.puts h params[:message]}
You have to provide a virtual path relative to the web app when using Server.MapPath using the special character ~ which is a shortcut to the web app root directory. Now, the simplest way to do it is a follows...
System.IO.File.WriteAllText(Server.MapPath("~\messager.txt"), Request.Form["message"]);
this is assuming that the request actually contains the "message" form variable. Note that this approach will create a new file if it doesn't exist or will override it if it does exist.
However, in ASP.NET Web Forms we usually use server controls such as a TextBox, if when posting the page the message is set to a text box, then a better way to retrieve this message in OOP-style would be...
TextBox_ID.Text;
where TextBox_ID is the id of the TextBox
Edit
if Request.Form["message"] is coming in empty. Make sure that:
there's a text input element named message
there's no other element with the same name attribute
the input element is inside the form tag with runat=server attribute
you are posting back the page instead of issuing a GET request

HtmlAgilityPack Issue in reading html

I am reading websites in C# and get contents as string....there are some sites which do not have well formed html structure.
I am using HtmlAgilityPack which give me issue in that case.
Can you people suggest me what to use so that it can read whole string and i can get useful informations?
Here is my code
htmlDoc.LoadHtml(s);
if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
Why this IF Condition is true for my case
What is the error you're getting? Is it throwing an exception or are you just wanting to see the error? Hard to tell what your actual question is.
You can see the markup errors in the HTML by using the HtmlDoc.ParseErrors property and iterate though them. This will give you the line number, code and type of error.
You can see more info about this property here
https://stackoverflow.com/a/5367455/235644
Edit
Ok so you've updated your question since my reply. You can see the specific error that's returning true in your IF statement by looping through the .ParseErrors are described above.
Second Edit
You can loop though the errors like so:
foreach (var error in htmlDoc.ParseErrors)
{
Debug.WriteLine(error.Line);
Debug.WriteLine(error.Reason);
}
You have to fix the bug in your HTML, and after it is valid you can go on.
Here is the same problem:
Invalid HTML in AgilityPack
If your html is external and you can't fix it, you can first run it through a cleanup preprocessor, then parse it with HtmlAgilityPack.
This will attempt to fix as many issues as possible automatically before HtmlAgilityPack gets to see it. The most popular HTML cleanup tool is Tidy. See the .NET version here:
http://sourceforge.net/projects/tidynet/

Problems with Request.QueryString. Reads cache instead of URL

I'm trying to retrieve the value of myID from my URL.
I'm testing this using <%=Request.QueryString["hotelid"] %>.
It only works the first time the page is loaded either in a new browser, or if my project has been rebuild.
My URL string is typical: http://my/path/to/site/?hotelid=2.
If I try <%=Request.QueryString %>, I'm also getting other values as well. Values I do not see inthe URL string.
What am I missing here?
Update:
Using <%=Request.RawUrl%>, I get the following results:
/Util/NotFound.aspx?404;http://localhost/en/Tjenester/Hotellguiden-2/Hotel-informasjon/?hotelid=3
I have NO idea what the /Util/NotFound.aspx?404 is or where it comes from.
My URL looks like this:
http://localhost/en/Tjenester/Hotellguiden-2/Hotel-informasjon/?hotelid=2
Update 2:
I'm currently investigating if it is EPiServer CMS that is using some kind of caching.
Update 3:
I have solved it. EPiServer is using EPnCachePolicyTimeout which isset to 1 hour. Setting this to 0 (zero) solved my problem.
Sometimes is really helps just writing aboutthe problem here, talking "aloud" about it and voila :)
You need to turn off caching or add your parameter names to the config attribute httpCacheVaryByParams or overwrite the custom caching key method and make it diff on every querystring parameter.

Categories