How to inspect an element in c# like firebug does? - c#

Is there a way to inspect/spy elements in a web browser like firebug does when we move the mouse over the webpage? How to to it in c#??
EDIT:
Actually I just want to get the HTML source code from the tagged element.
Best regards.

Asp.Net framework uses "HTMLTextWriter" class to generate the HTMl markup for server controls.If say for example , you want the HTML markup for gridview control , then you can make use of this class and its associated member functions to get the markup.But again its all a part of server side logic and achieving the same through client side code is not that easy.If you can provide more information on whats the exact requirement then it will be quiet nice.

You cannot interrogate dynamically the client side rendering of a server side control via the browser. There is a disconnect between the server and client side that it maintained through the .Net viewstate model. You can generally tell which DOM elements have been generated via server side code through the ID having an extended value but this is not any guarantee etc. In .Net 4.0 the client side IDs will be able to be set via the server side so even this is tenuous.
As James has said, you should use firebug to determine the output on the client side and then tailor your server side rendering accordingly.
Can you provide a more detailed example of what you are trying to achieve and perhaps there is a further solution / explanation that can be offered?

Related

How does Microsoft Razor Syntax run server side code without exposing it to the client?

I am having trouble wrapping my head around how Razor syntax works.
It is my understanding that it will allow you to embed server-side code directly into the page, but it keeps all of that from the client even though the client can interact with it.
I'm used to ASP.net web views and things of that nature - does the Razor syntax essentially do postbacks and all of the code is contained within the page, or is the way that the client interacts with the server-side code fundamentally different?
If this is too open-ended, please leave me comments as to how to focus the question more. I fear I don't yet understand enough to make finely-focused questions.
Thanks!
From my understanding:
1. How Razor syntax works:
You can see the Razor is similar to the scriplet in Web Form. For example, you want to get the Name of the Human class, in .cshtml file, you write:
<div>Name is #Model.Name</div>
And in aspx, you write:
<div>Name is <%= Human.Name %></div>
Both Razor and scriplet will be processed before returning the HTML files to client. Follow the above example, if you view the source of your HTML web page, you will see (Forte is just an example):
<div>Name is Forte</div>
Because the code was processed, so, what the client see is the HTML result only.
2.How do clients interact with server?
In Web Form, when you want to go to server (like handle click button event), you can generate the function to call by set OnClickListener for the button, and everything is done automatically for you.
However, in MVC.NET, you have to do it through Ajax call, or put your button in a <form>.
If you have any question, feel free to let me know :)
mvc runs all that stuff server side and provides the client with the resulting html/javascript generation.
Lets say you have this in a view
#{ var var1 = "Hello World"; }
<p>The value of var1 is: #var1</p>
Everything happens on the server
When a user is requesting this page the server gets the text above and sends it to the view engine.
Then the server runs the text line by line and "compiles" it.
Then the server snds the result back to the user:
The value of var1 is: Hello World
If the user makes a view source he will see only:
<p>The value of myMessage is: Hello World</p>
So the user on the client writes a simple URL , and the result he is getting is ONLY the line above.
Essentially it compiles the view like any other csharp/vb.net file. However, it does it on-the-fly (the first time you hit it, and the underlying file hasn't changed).
If you want to see what the generated code looks like, take a look at https://github.com/RazorGenerator/RazorGenerator This allows you to actually generate the same code as part of MSbuild and deploy it.

Accessing C# function in Javascript

I think there is something that I don't understand as I proceed forward in my project of importing D3 visuals into Spotfire.
I currently have implemented a D3 visualization into Spotfire by using Awesomium's embedded browser and these lines:
string myString = System.IO.File.ReadAllText(#"C:\Users\leear\Desktop\SDK\SDK\Examples\Extensions\D3Visualizations\Gauge.html");
webView.LoadHTML(myString);
The HTML of Gauge.html contains javascript code that runs all the necessary things to create the visualization.
However, I want to be able to access/run C# functions and variables inside the Gauge.html file. I am envisioning something like this:
for (var value in <%=Spotfire.getCurrentColumn()%>) {gauge.redraw(value)}
My project is currently structured just for the C# code to read and write all the HTML from a file into Awesomium's embedded browser.
How would I do this? Where does aspx.NET fit into this, if at all?
Thanks
You can't; javascript is client-side, and ASP.NET is server side. ASP.NET basically generates HTML and javascript, and once that rendering is done the page is processed the client-side takes over, which it knows nothing of ASP.NET. It's perfectly fine for ASP.NET to spit out JS becuase it's RENDERING it, but the client-side PROCESSING of JS, which is where you are trying to call a server-side method knows nothing of ASP.NET. You'd have to move the logic to the client, or have the client talk to the server using javascript.
I can't advise further as I don't know what that method does.
"You can't; javascript is client-side, and ASP.NET is server side. ASP.NET basically generates HTML and javascript"....
This is absolutely correct. Client and server are two different worlds...
You have a couple of options if you need to get code-reuse.
Look into a C# to javascript compiler..and make sure your C# functions don't depend on anything related to the server or its runtime.
Otherwise, consider exposing your server functionality as a web service that takes input of some form and returns output as JSON for use on the client side.

How to host my ASP.NET Application on GoDaddy?

I want to be able to upload my work to my site, but when I view the Default.aspx file in a web browser, I just see the code, not the actual "rendering" of the code. Any know know what I am doing wrong?
Here's an image of what I mean:
You need hosting that supports ASP.Net, otherwise server simply will render page as text. There are plenty around - search and find one that fits your needs/budget.
Note that the same would happen with any other server side language if uploaded to host that does not support that particular language.

How to call a Web Page an automatically fill up a Form passing a String

I use asp.net 4 c sharp.
I would like populate a input text form with a string sent by an User.
The destination page is:
http://www.maxmind.com/app/locate_demo_ip
NOTE: im not the developer for the target page.
Here ho should work:
When a visitor from my site click a link (Ip address)
it will be sent to: http://www.maxmind.com/app/locate_demo_ip
and the TextBox automatically populates with the value (Ip address the user has clicked).
The user Will manually click the button "Look Up IP addresses" in maxmind.com to have the result.
Any idea how to do it? Maybe a sample of code?
Thanks guys as usual for your great support! :-)
if you can, generate a link with this form :
http://www.maxmind.com/app/locate_demo_ip?ip=XX.XX.XX.XX
then, the page can access this value using txt1.Text = Page.Request.QueryString["ip"]
[Edit] it assumes that you are the developer of the target page... is it ?
You tells me you are not the developper.
Either maxmind provide an url syntax similar to the one below (check if there is an api section, or you will have to inject with javascript the value. In this case, you have to know :
for security reason, to avoid a cross site scripting attack, you can't pilot an external site from one page to the other. You can maybe add your application in the trusted zone of the client computer, but it's not possible in an internet application
nothing guaranties that the html structure of maxmind won't change in the future. you can't rely on this.
An another approach would be to "proxy" the features of maxmin by calling yourself from your server application the target page, with a Http Post request. Then you can parse the results to use it on your application. Again, some limitations are to consider :
maxmind may disallow such calls. They may want the user to use their application
again, the target page may change its structure and the textbox names
parsing the result can give headache... and the output structure may change (again)
you have to handle yourself the UI related to this feature.
A final though : what is your goal ? maybe there are other ways to achieve it.

Update a field from server without reloading the existing page using simple javascript

I want to change a value of a field say document.getElementById('reloader').innerHTML = updated value from Server
I do not want to use Ajax, PHP, ASP, JSP .. or anything like these.
Is it possible by using simple javascript?
Server is C# 's application made by using HttpListener.
Please question if needed more info.
You can't do it without using something like AJAX, unless you're willing to update the entire page. Somehow, the browser has to contact the server, trigger an action there, and receive and process the response.
Thus, you can use XMLHttpRequest, or you could use JSONP or something similar. In any case something has to be written on the server to respond to the request and supply the data, and that's not going to be "simple Javascript" unless you've got a server-side Javascript solution (which is not impossible of course, but probably unlikely).
I am not sure why you dont want to use Ajax. But i believe the only other workaround then can be use an iframe on your page point to the server script and write javascript to read it. I havent tried it recently but i believe it should work

Categories