Removing a specific query from url using jquery [duplicate] - c#

This question already has answers here:
How can I delete a query string parameter in JavaScript?
(27 answers)
Closed 9 years ago.
Good morning guys, i have encountered a problem here.
This is my current URL:
blabla/shoe?type=boot&zoom=true
i want to remove the "&zoom=true" part, without reloading the page.
But bare in mind that the URL may also look like this:
blabla/shoe?zoom=true
how do i accomplish this, can someone give me an example of Jquery statements. So can start from there. thank u in advance
The reason why i wanna do this is because of the following:
<div class="standard" style="<%=isZoom?"":"display:none;" %>">
isZoom() is checking for any zoom query in the URL, i want the &zoom=true to go away so that the div can be shown

Changing the URL in the browser will reload the page. What's more, the loaded page will not contain your ASP.NET condition. It will only say style="display: none;", so even if you could change the URL without reloading the page, you'd still need to reload the page to have ASP.NET render something else.
The good news, though, is that you can show a div without changing the URL or reloading the page:
$('.standard').show();

Related

MVC 5 Calling C# function from button in view [duplicate]

This question already has answers here:
HTML button calling an MVC Controller and Action method
(19 answers)
Closed 5 years ago.
Looking for a way to call a c# function with a button inside one of my views? This seems like something trivial, but I haven't been able to find a solution for this. Any help is appreciated!
This is kinda how I expected it to be implemented, that or a #Html.Button
<input type="button" value="Sign Out" onclick="#SignOut()"/>
There is no simple way of dynamically executing server function inside the Razor views.
You can however using button redirect the user to another route that will execute the server function.
Using the #Html.ActionLink("your text", "actionName", "controllerName") Razor helper.
Doing so you will create an element that on click will redirect the user to the specified route.

Redirect if JavaScript is not enabled [duplicate]

This question already has answers here:
How to detect if JavaScript is disabled?
(39 answers)
Closed 5 years ago.
I am working on a logic where I want user to be redirected to a particular page if JavaScript is not enabled. I have put a meta-tag which will refresh every few seconds and if JavaScript is enabled and I want to use JavaScript to remove that element.
I have tried many things but I have been unsuccessful in removing the tag. Also I tried to empty the content of the tag but it still redirects.
Is there any other way to deal with this issue?
I am posting some code for you to take a look, I just grabbed it from the web but seems to be emptying the contents when I debug through the code:
var m = $('meta');
for (var c = 0; c < m.length; c++) {
m[c].parentNode.removeChild(m[c]);
m[c].content = '';
}
I am also open to a server side solution but the client does not send much information such as if javaScript is enabled or not.......
Try this:
// THIS DOES NOT WORK
$( 'meta[http-equiv="refresh"]' ).remove();
It certainly depends on how soon your jQuery code executes and how soon your refresh triggers...
Update: The above method does not work. Even though the meta element is removed from the DOM, the browser still executes the refresh.
Live demo: http://www.ecmazing.com/misc/test-removing-meta-element/
I believe you should also be able to do this:
<noscript>
<meta http-equiv="refresh" content="...">
</noscript>
So, if you wrap your meta element in a NOSCRIPT element, it should only be parsed if JavaScript is disabled.
Read about the NOSCRIPT element here: https://developer.mozilla.org/en/HTML/Element/noscript

How do I create hyperlinks from resource files?

I have some text which is loaded from a resource file. Ordinarily, to get dynamic content I would use:
string.Format(GetLocalResourceObject("SomeText"), PhoneNumberAsString)
I want to do the same with a link, only the link needs to be application relative as I have URLs like mysite.com/page.aspx and mysite.com/fr/page.aspx.
I normally use an <asp:HyperLink /> tag to create the links as I can then just put a squiggle at the start NavigateUrl="~/page.aspx". However, I don't know of a way to get a dynamic HyperLink to appear as a string without adding it as a control to something.
Simply writing ToString() outputs System.Web.UI.WebControls.HyperLink..
How do I get a link out of a resource file and make it into a hyperlink using ASP.NET Webforms?
UPDATE
With some help from the answers I now have the following code on my page:
<p><%= string.Format(GetGlobalResourceObject("Resource", "MoreThan1000Users").ToString(), ResolveUrl("~/contact-us.aspx")) %></p>
and in my resource file I have:
If you would like more than 1000 users please call our sales team.
Does this seem like good practice or is there another way to achieve what I'm doing? I don't know if I should be happy or not that there is HTML inside the resource file.
Since you haven't posted code, I'm guessing somewhere you have a HyperLink WebControl object that you're hitting ToString() on. If that's the case, you can access the URL associated with it using its myHyperLinkControl.NavigateUrl property.
If you're storing the link in your resource with a squiggle/tilde (which is good) then you can replace the squiggle with your application location. If you have a control/page, then you can easily call its ResolveURL method (which takes the tilde and automatically replaces it) There's some existing solutions if you don't have a control/page reference with your context, then there's some discussion to do that here: ResolveUrl without an ASP.NET Page
I guess this is what you want:
Server.MapPath("~/page.aspx")
That will work inside your aspx and your code-behind.

C# - Get JavaScript variable value using HTMLAgilityPack

I currently have 2 JavaScript variables in which I need to retrieve values from. The HTML consists of a series of nested DIVs with no id/name attributes. Is it possible to retrieve the data from these variables using HTMLAgilityPack? If so how would I go about doing so, if not what would be required, regular expressions? If the latter, please help me in creating a regular expression that would allow me to do this. Thank you.
<div style="margin: 12px 0px;" align="left">
<script type="text/javascript">
variable1 = "var1";
variable2 = "var2";
</script>
</div>
I'm assuming you are trying to scrape this information from a website? Most likely one you don't have direct control over? There are several ways to do this, I'll go easy to hard( at least as I see em):
Ask the owner (of the site). Most of the time they can give you direct access to the information and if you ask nicely, they might just let you have it for free
You can use the webBrowser control, run the javascript and then parse values from the DOM afterwards. As opposed to HttpWebRequest, this allows for all the proper values to be loaded on the page and scraped. Helpful Link Here.
Steal the source with Firebug. Inspect the website with Firebug to see which URLs are called from the background. Most likely, its using an asynchronous request to retrieving the updated information from a webservice. Using Firebug, you can view this under the NET -> XHR. Look at the request and the values returned, you can then retrieve the values your self and parse the contents from the source rather than scrape the page.
I think this might be the information you were looking for, but if not let me know and I can clarify/fix answer

c# webbrowser show what you want

i want create small web browser , tiny and fast
but i have problem ,
let me explain :
1 - user enter site : google.com
2 - c# program get google.com
3 - find <td nowrap="" align="center">
4 - in web browser only show that area
i dont know where i must start ,
thanks
Ok, I'm going to try answer your question, but I am deciphering as well.
Create a WebBrowser control on your form. (2.0 is fine for what you need) and .Navigate("http://www.google.com");
Get the source code from the Document. You can do this as follows: string source = _WebBrowser.Document.Body.OuterHtml;
Use string manipulation to get to the area on the page you need. For instance .SubString() functions
Save the text into a file, or stream and load it into the WebBrowser control, or replace the pages Document HTML with just the HTML you are wanting to show.
Okay! Looking at the comment it seems you want to request for a page using c# and show only one part of the page. In your case its that specific <td> . Please correct me if I am wrong.
Other than what Kyle has mentioned. Check out HTML agility Pack. It might be of interest to you.

Categories