I am trying to integrate disqus comment counts in bloq summary.
#{
Orchard.ContentManagement.ContentItem contentItem = Model.ContentPart.ContentItem;
string bodyHtml = Model.Html.ToString();
var body = new HtmlString(Html.Excerpt(bodyHtml, 8000).ToString().Replace(Environment.NewLine, "</p>" + Environment.NewLine + "<p>"));
}
<p>#body #Html.ItemDisplayLink(T("more").ToString(), contentItem)</p>
so i need to concatinate #disqus_thread to the href of the contentItem link.
I cant use any plugin for implementing disqus. How can i edit the href?
If you are looking to get the display url of a content item, us the Url helper, e.g.:
#T("more")
Now you have full control over the href, allowing you to append whatever querystring parameter you need.
Related
i want search spacial value in html code by webbrowser in c#. for example html code<span class="pulser " data-dollari="164.843956376000000" eq_toman="_XcUOV" pulser-change="_OiuVD" pre-dollari="164.964899983000000">$164.97</span>i need Getting the value "164.964899983000000" and another value html code.
If I understand you correctly, you want to get an element from a site and get its attribute values like 'pre-dollari'.
For c#, you can use ScrapySharp , it's a library where you can simulate a webbrowser and scrape its contents. You can use it alongside htmlAgilityPack
to effectively traverse the elements.
So for your case, it could look like this.
// get your Url
Uri url = new Uri("Yoursite.com");
// open up the browser
ScrapingBrowser browser = new ScrapingBrowser();
// navigate to your page
WebPage page = browser.NavigateToPage(url, HttpVerb.Post, "", null);
// find your element, convert to a list and take the first result [0]
HtmlNode node2 = page.Find("span", By.Class("pulser")).ToList()[0];
// and now you can get the attribute by name and put it in a variable
string attributeValue = node2.GetAttributeValue("pre-dollari", "not found");
// attributeValue = 164.964899983000000
Im using HTML Agility Pack, and Im trying to replace the InnerText of some Tags like this
protected void GerarHtml()
{
List<string> labels = new List<string>();
string patch = #"C:\EmailsMKT\" +
Convert.ToString(Session["ssnFileName"]) + ".html";
DocHtml.Load(patch);
//var titulos = DocHtml.DocumentNode.SelectNodes("//*[#class='lblmkt']");
foreach (HtmlNode titulo in
DocHtml.DocumentNode.SelectNodes("//*[#class='lblmkt']"))
{
titulo.InnerText.Replace("test", lbltitulo1.Text);
}
DocHtml.Save(patch);
}
the html:
<.div><.label id="titulo1" class="lblmkt">teste</label.><./Div>
Strings are immutable (you should be able to find much documentation on this).
Methods of the String class do not alter the instance, but rather create a new, modified string.
Thus, your call to:
titulo.InnerText.Replace("test", lbltitulo1.Text);
does not alter InnerText, but returns the string you want InnerText to be.
In addition, InnerText is read-only; you'll have to use Text as shown in Set InnerText with HtmlAgilityPack
Try the following line instead (assign the result of the string operation to the property again):
titulo.Text = titulo.Text.Replace("test", lbltitulo1.Text);
I was able get the result like this:
HtmlTextNode Hnode = null;
Hnode = DocHtml.DocumentNode.SelectSingleNode("//label[#id='titulo1']//text()") as HtmlTextNode;
Hnode.Text = lbltitulo1.Text;
I'm displaying a list of filtered items in a page, and now I have to limit the displaying by paginating the results.
So if I have url parameters like these:
example.com/?category=pizza&period=today
where both category and period can also not being showed:
example.com/?period=today
example.com/
how can I add a "Next page" in the end that keeps any previous parameter and adds
&pagenum=5
or if there are no parameters:
?pagenum=5
Tnx in advance!
For serverside
string url = Request.Url.GetLeftPart(UriPartial.Path);
url += (Request.QueryString.ToString() == "" ) ? "?pagenum=1" : "?" + Request.QueryString.ToString() + "&pagenum=1";
You can pass in the page number depending on how you are handling this.
For ASP.Net use the following:
string temp = Request.QueryString["yourParamName"];
Fissh
How do I request querystring using javascript from URL
e.g : http://localhost:1247/portal/alias__MySite/lang__en/tabid__3381/default.aspx
I want to get tabid...
var tabid = '<%= Request.QueryString["tabid"] %> ';
Above code works only in aspx page
but i dont need it, any ideas? thanks
There is now a new api URLSearchParams. Use that in conjunction with window.location.search
var urlParams = new URLSearchParams(window.location.search);
console.log(urlParams.get('tabid'));
If your browser does not support URLSearchParams, you can create a custom fallback function:
function getParam(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
console.log(getParam('tabid'));
Don't know why but I've always found the javascript for querystring data fetching a bit hacky. if you don't need this value on the initial page load then perhaps you could use Request.QueryString in the code and set the value to a hidden field, which your javascript will read from?
Try this, It is working perfectly for me.
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var tabId=getParameterByName("tabid");
I bet there is a server-side rewrite (DotNetNuke?), so the aspx.cs "sees" the redirection target which contains the correct QueryString.
For the client, you have to use another mechanism because the browser only "sees" the public URL. In this case, a Regex that picks the number behind 'tabid_' and before the next slash should work. This would be the same number (page id?) that the aspx page "sees".
This is what I used:
<script type="text/javascript">
function QueryString(key) {
//Get the full querystring
fullQs = window.location.search.substring(1);
//Break it down into an array of name-value pairs
qsParamsArray = fullQs.split("&");
//Loop through each name-value pair and
//return value in there is a match for the given key
for (i=0;i<qsParamsArray.length;i++) {
strKey = qsParamsArray[i].split("=");
if (strKey[0] == key) {
return strKey[1];
}
}
}
//Test the output (Add ?fname=Cheese&lname=Pizza to your URL)
//You can change the variable to whatever it is you need to do for example, you could
//change firstname to id and lastname to userid and just change the reference in the
//document.write/alert box
var firstname = QueryString("fname");
var lastname = QueryString("lname");
document.write("You are now logged in as " + firstname + " " + lastname + "!");
</script>
You can replace document.write with alert and it would give you an alert box instead!
I used this on my website. Its not done yet but when it is it will be at zducttapestuff.com
The output will look like this: You are now logged in as Cheese Pizza!
This is very unsecure for Passwords though since the password will be shown in the url.
I'm making a Car dealership website, and in my webpage to do an advanced search i'd like to make it possible to display some details of the car then a link to the actual page of the car. Right now i have a
StringBuilder tableBuilder = new StringBuilder();
if(reader.HasRows)
While (reader.Read())
{
string col0 = reader["ID"].ToString();
string col1 = reader["Make"].ToString();
string col2 = "LINK..."
I'd like to replace "LINK..." with a redirect to a different page+reader["ID"].ToString();, and I can't seem to find any decent material that says how to incorporate it with this. The way that it would be nice would be so that for all the cars that match the criteria, there is a link to each details page.
The easiest way is to simply emit the href directly:
string col2 = "<a href='somepage.aspx?someparam=someval'>Link Text</a>