I created a hyperlink control extended from HyperLink, but I do not know how to override the navigateurl property, the problem is: im using a jquery library that depends on the url to look like this
#TB_inline?height=285&width=510&inlineId=contactUsContent
problem with .net is that it reorders this into:
../controls/?height=285&width=510&inlineId=contactUsContent#TB_inline
how can i force it to accept my string?
i think i was too hasty to ask this question, the simple solution was to decieve the hyperlink into making it an absolute url instead of relative, so all i had to do is insert a "/" at the beginning of the url
silly me!
Related
I use .net 4 and c#.
I have a asp.net Page wit an HyperLink.
<asp:HyperLink ID="uxLink" ClientIDMode ="Static" runat="server"></asp:HyperLink>
In my code behind I use the HyperLink ID="uxLink" to change some properties.
In my browser the code generate is:
<a id="uxLink" href="/blog/5/test.aspx">Test link</a>
I would need omit the id from the source code generated in the browser so it should look:
Test link
I tried to play with ClientIdMode but with no succe... Any idea how to do it? Thanks
If you remove ClientIDMode ="Static", the framework will generate a "big unique" ID for the element, but still, there will be an ID.
Having an ID is fundamental if you want to handle the elements in client-side script. The IDs should not be removed.
If you don't want them, just don't use ASP.NET components, use the <a> tag itself.
Update
By the way, supposedly there's a way to do what you want in ASP.NET 4. It's described here: http://www.codeproject.com/Tips/208323/Disable-ClientID-for-any-control-on-ASP-NET-Page?display=Print
I haven't tried it, I'm just pointing you into a direction. You should be aware of the implications of not having a ClientID, though. Specially for Postback controls. Read the article.
The easiest solution is to change the ID propriety for the control in code behind before rendering the page to NULL.
in my example:
myLink.ID = null;
This would generate no ID at the Browser resulting in:
Test link
I find this useful trick on this website:
http://www.dotnetperls.com/remove-id
I am writing a simple personal app that has a browser control and I want it to automatically "Refresh" gmail to check it more often than it does by default. There are monkey scripts that do this but I'm trying to add my personal style to it.
Anyhow, I've looked around and found everything but what I can do in csharp using the browser control.
I found this:
// Link the ID from the web form to the Button var
theButton = webBrowser_Gmail.Document.GetElementById("Refresh");
// Now do the actual click.
theButton.InvokeMember("click");
But it comes back with null in 'theButton' so it doesn't invoke anything.
Anyone have any suggestions?
It's been awhile since I've used JavaScript, but given the other answers and comments that there is no real ID associated with the element, could you do something like the following:
Search all Div's with an attribute of Role == 'Button' and an InnerHtml == 'Refresh'.
Once the correct InnerHtml is found, get the Element.
Invoke the click on the found Element.
Again, this may be blowing smoke, but thought I'd throw it out there.
edit: Just realized you are doing this with C# and a browser control; however, the concept would still be the same.
The best suggestion I could give you at this point involves an existing API that is used for .NET web browser based automation:
http://watin.org/
Since the div tag with the desired button really only seems to identify itself with the class name, you could use the Find.BySelector(“”) code included with the most recent version of watin.
Is it possible to scrape all the text from a site that was navigated to by WebBrowser control without looking at the source?
David Walker's method is great when one don't need any info from the header nor non main part of the webpage. if one need something outside inner text, there is only two options, one is to parse with "getElement".
the other one is issue commands (Document.ExecCommand) to webbrowser to select all and copy to clipboard:
wb.Document.ExecCommand("SelectAll", false, null);
wb.Document.ExecCommand("Copy", false, null);
then finally string content=clipboard.getText();
Please note the spelling and syntax may not be correct, I'm recalling from my memory
string browserContents = webBrowser.Document.Body.InnerText;
You use the DocumentText property or the WebBrowser control.
This property is what holds the HTML of the site you have navigated to.
Update: (following comments)
If you want to parse the HTML and get the text parts of it, I suggest you use the HTML Agility Pack.
i have a problem when i RewritePath in HttpContext,
context.RewritePath(Utility.WebRoot + "List/Add.aspx", false);
It work fine to rewrite the url: http://localhost/List/Add
But when i hit the button it redirect me to http://localhost/List/Add.aspx
Is there a good way to "stop" the redirection to the .aspx page and just leave it on http://localhost/List/Add ?
Thanks for help
There is an issue with the From tag. You have to use a Control Adapter like this one:
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Go to the "Handling ASP.NET PostBacks with URL Rewriting" section.
This will help:
http://www.codeproject.com/KB/aspnet/SmartFormControl.aspx
Basically the idea is to create a new Form control (I called my "ActionlessFormControl") that derives from the .Net Form control. The gist of it is that you override the rendering of the attributes and set your own value for the "action" attribute. What I do in mine is I remove the "action" attribute altogether which will post back to the same URL. Meaning, your page will post back to "/List/Add".
The benefit from using the inherited control is that you don't have to "register" each page. This will allow you to have dynamic content/URLS post back correctly.
I am trying to change a label's text by using server-side JavaScript (onclick) and C# within the page_load event. For example, I would like to write something like the following:
Label1.Attributes.Add("onclick", "Label2.text='new caption'")
Does anyone know the correct code for this? Also, what is this type of code referred to; is it just JavaScript or JavaScript in C# or is there a specific name? Lastly, does a book or online resource exist that lists the choices of control.attributes.add("event", "syntax") code to use with C#?
There is no server-side Javascript (unless you change to a platform other than ASP.NET where you actually use Javascript as server language). What you are doing is adding an attribute to the html tag, and the code will be executed entirely on the client side.
First, let's look at how it's done in HTML without the server side code and server side controls:
<span onclick="document.getElementById('Label2').innerHTML='Thank you';">Click me</span>
<span id="Label2"></span>
To use Label controls instead, setting the onclick attribute from server side code, you would do like this:
Label1.Attributes.Add("onclick", "document.getElementById('Label2').innerHTML='Thank you';");
This will work as long as the controls are not inside a naming container. If they are, the id of the controls are prepended with the name of the container to keep them unique, so you need to use the ClientID property to find out what their final id is:
Label1.Attributes.Add("onclick", "document.getElementById('" + Label2.ClientID + "').innerHTML='Thank you';");
The ClientID always contains the id that you can use to access the element from Javascript, so the last code always works regardless if the control is in a naming container or not.
To find out what attributes you can use, you should look at the HTML documentation, for example the Internet Explorer documentation for the span element. When looking at the documetation for a specific feature, notice the Standards Information, as that will tell you if it works in any browser or just in Internet Explorer.
The code above adds JavaScript to a server control rendered on the client. Take a look at this MSDN article - Using JavaScript Along with ASP.NET for more information.
IIRC, you will need to reference Label2 by its ClientID and will need to write some JavaScript to change the label's text value (I think ASP.NET labels get rendered as <span> tags).