Get full source of a webBrowser - c#

I have a webBrowser:
webBrowser1.DocumentText = #"<html lang='en'>
<head>
<meta charset='utf-8'>
<title></title>
<style type='text/css'>
.red
{
color: red;
}
</style>
</head>
<body>
<div class='red'>red text</div>
sad adad a das
</body></html>";
I want to get the full source of the webBrowser:
textBox1.Text = webBrowser1.DocumentText;
But it results only:
<HTML></HTML>
It works if I display in a MessageBox before set the textBox1.text:
MessageBox.Show(webBrowser1.DocumentText);
It's weird. How can I get the full source?

Here is a proper way to display HTML from string in WebBrowser control
var html = #"<html lang='en'>
<head>
<meta charset='utf-8'>
<title></title>
<style type='text/css'>
.red
{
color: red;
}
</style>
</head>
<body>
<div class='red'>red text</div>
sad adad a das
</body></html>";
webBrowser1.DocumentText = "0";
webBrowser1.Document.OpenNew(true);
webBrowser1.Document.Write(html);
webBrowser1.Refresh();
// Will return html you provided
textBox1.Text = webBrowser1.DocumentText;

To answer your initial question directly, how to get FULL SOURCE no matter what:
WebBrowser1.Document.GetElementsByTagName("HTML").Item[0].OuterHtml;
Make it a habit to use this and NOT DocumentText because if you make any changes to DocumentText after it's been set, for example, changing the InnerHTML of a tag, those changes wont save to DocumentText.
I just slapped a TextBox onto one of my WinForms and updated the text to the above code and it shows all my HTML without issue. Here's an example of me filling in my WebBrowser in case you've got a typo or something in your code:
WebBrowser1.Navigate("about:blank");
WebBrowser1.Document.OpenNew(false);
WebBrowser1.Document.Write("<html><head><title></title></head><body></body></html>");
I never had any luck writing the DocumentText directly. This method worked without issue.

Related

How Can I Make Right To Left Navbar In My Webform?

I'm just recently start Asp.net And now I'm gonna to make right to left navbar.
Try some code but all was left to right.
in case you using bootstrap use : class="navbar-right"
in case you didn't use it you should better use it )
but if you still didn't want to you can use dir="rtl" in your nav header tag or creating class and use it like that
<!DOCTYPE html>
<html>
<head>
<style>
.rtl {
direction: rtl;
}
</style>
</head>
<body>
<Navbar class="rtl">your text
...
</Navbar>
</body>
</html>

Unable to dispaly markers on map using mapbox ,leaflet Omnivore

I am trying to use CSV file to display markers on map using mapbox and leaflet. I found one example in mapbox documentation , I am trying to use the same example , I just changed the CSV file but it is not displaying markers on map. I just started using map box so desperately looking for some help.
my CSV file looks like this
Value,FacTy,Latitude,Longitude
1,112,42.27426,-83.365717
2,113,42.274082,-83.3623
3,30,42.337196,-83.487672
Here is my code snippest
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Loading markers from CSV</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.2.0/leaflet-omnivore.min.js'></script>
<div id='map'></div>
<script>
var map = L.mapbox.map('map', 'examples.map-i86nkdio')
.setView([42.274082, -83.362300], 8);
omnivore.csv('latlon.csv',null,L.mapbox.featureLayer()).addTo(map);
</script>
</body>
</html>
Looks like you're missing a linebreak before the first row of your data. Here's a fixed example.
Value,FacTy,Latitude,Longitude 1,112,42.27426,-83.365717
2,113,42.274082,-83.3623
3,30,42.337196,-83.487672
should be
Value,FacTy,Latitude,Longitude
1,112,42.27426,-83.365717
2,113,42.274082,-83.3623
3,30,42.337196,-83.487672
I was having the same issue as you, and then realized that it was a problem with the data. In order to log those errors on the console, you have to use:
omnivore.csv('your_file.csv', null, L.mapbox.featureLayer()).addTo(map)
.on('error', function(error) {
console.log(error);
});
And it will tell you which line is not working, such as an invalid lat or long. More info.
Hope this helps!

How to generate css by database in asp.net..?

I want to change the content of style sheet dynamically like:
.menu
{
color: #333333;
Font-size : 12px;
}
I want to change the color and font size dynamically.
How to replace value of color (like #333333 to #ffffff) and font size (12px to 14px) dynamically.
I am finding the way to use variables in stylesheet, and assigning it to attributes that can make my work easy.
Waiting for reply with example.
If you use asp.net, use inline html. Read here
<div style="font-size: <% Response.Write(i)%>">
Hello World<br />
</div>
I am not pretty much sure that you can use variables in stylesheets, what I think a way around for it is to generate the style sheet at run time and assign it to the page.
In you asp.net page you can have like:
<head>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<asp:literal id="literalCss" runat="server"></asp:literal>
</head>
and than in your code behind you can use:
private void Page_Load(object sender, System.EventArgs e)
{
// create css file here for the specific user and save it in a folder,
// give a meaning full name to file, if user specific you can append user id in name like
string fileName = "cssFile_" + userid + ".css";
literalCss.Text = #"<link href='/style/" + fileName + "' rel='stylesheet' type='text/css' />";
}
I hope it can help you out.
You may use JavaSctipt with JQuery:
$("#myButton").Click(function()
{
$(".menu").css({"color":"#ffffff","font-size":"14px"});
});

Replace size parameter in css

I want to replace all font-size-parameters in a html document (css attributes).
I'm using .net with c#.
I guess it could be done with some regular expression.
Am I forgetting some other ways to set the font size?
Example:
<html>
<head>
<style type="text/css">
.t {
font-size: large;
}
</style>
</head>
<body>
<span style="font-size: medium" />
</body>
</html>
into:
<html>
<head>
<style type="text/css">
.t {
font-size: large_replaced;
}
</style>
</head>
<body>
<span style="font-size: medium_replaced" />
</body>
</html>
if you use relative unit like em, ex etc for all font dimensions in your page. By adjusting
only html elements' size you manage all fonts
big fonts
html{
font-size:18px;
}
smaller fonts
html{
font-size:18px;
}
you can manage that form javascript, better (also using cookies).
I ended up using the following regex to find where to replace:
/style=\"[.]*font-size:(?<size>[^;]*);[^\"]*[\"]/
/<style[^<]*font-size:(?<size>[^;]*);[^<]*[<]/

Set focus to textbox

In my web page there is a textbox with width and height equal to 0. This textbox is used to get the scanned bar code value which should not be visible to the user.
Needs:
I want to set focus to the textbox, when i click anywhere in the form.
I want to make the cursor invisible.
Geetha.
As for setting focus,
$('#idOfTextBox').focus();
will do the trick. You can add that to any click handler, such as
$('#idOfFormOrParentDiv').click(function() {
$('#idOfTextBox').focus();
$(this).css('cursor', 'none');
});
As for hiding the cursor, you could apply a cursor: none to the form or parent div as a style or as in the preceding example change it's css via jquery.
The cursor:none is while the cursor is in the bounds of the element - though this behavior in it's entirety seems obscure and unnecessary (not to mention confusing to the user).
Example
Here's an example of using absolute positioning to both hide the input field and its cursor. It focuses the field on load, so if you type, then press the Go button, you'll see what you typed.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Test Page</title>
<style type='text/css'>
body {
font-family: sans-serif;
}
#myTextBox {
position: absolute;
left: -10000px;
top: 0px;
}
</style>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
<script type='text/javascript'>
(function() {
$(document).ready(pageInit);
function pageInit() {
$('#btnGo').click(go);
$('#myTextBox').focus();
}
function go() {
alert($('#myTextBox').val());
}
})();
</script>
</head>
<body><div>
<input id='myTextBox' type='text' size='1'>
<input id='btnGo' type='button' value='Go'>
</div></body>
</html>

Categories

Resources