pdf objects won't display in IE but will in Chrome - c#

I am at my wits end.
The following code displays a pdf to the user based on a query string and pulls the pdf from a file server. It works great in google chrome. However, I need this to work in IE as well.
When I use IE, it just shows a blank space where the pdf should be. Below is my aspx and C# file. Both browsers have adobe reader addons installed.
FRONT END:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="JobBookViewer.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Job Book Viewer</title>
<style type="text/css">
#form1 {
font-weight: 700;
width: 118px;
height: 217px;
margin-top: 15px;
}
</style>
<script type="text/javascript">
function SetPDFwindow()
{
var varclientscreenwidth = screen.width;
var varclientscreenheight = screen.height;
}
</script>
</head>
<body onload="SetPDFwindow()">
<form id="form1" runat="server">
<div style="width: 203px; z-index: 1; left: 7px; top: 4px; position: relative; height: 34px; right: 811px;">
<asp:Button ID="ButtonAbout" runat="server" BackColor="#B0F1FF" style="z-index: 1; left: 873px; top: 1px; position: absolute" Text="About" OnClick="ButtonAbout_Click" Visible="false" />
<asp:ListBox ID="ListBox1" runat="server" style="z-index: 1; left: 735px; top: 41px; position: absolute; width: 206px; height: 447px;" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" AutoPostBack =" true"></asp:ListBox>
</div>
<div id="chromecheck" runat="server" visible="false">
Chrome
</div>
<div id="iecheck" runat="server" visible="false">
We have detected that you are not using Chrome. If the program is not working, please switch to Chrome
</div>
<object data="data:application/pdf;base64
, <%= this.file %>" type="application/pdf"
style="z-index: 1; left: -3px; top: 1px; height: 210%; width: 612%; margin-top: 1px;" id="myPDF"></object>
<p>
</p>
</form>
</body>
</html>
CODE BEHIND:
using System;
using System.Web.UI.WebControls;
using System.IO;
using System.Drawing;
namespace JobBookViewer
{
public partial class WebForm1 : System.Web.UI.Page
{
public String file;
public String id;
protected void Page_Load(object sender, EventArgs e)
{
System.Web.HttpBrowserCapabilities browser;
browser = Request.Browser;
if (browser.Browser.ToLower().Equals("chrome"))
{
chromecheck.Visible = true;
}
else
{
iecheck.Visible = true;
}
if (!IsPostBack)
{
// myPDF.Style.Add("width", (Convert.ToInt32(clientScreenWidth.Value)-200).ToString());
file = fnFilePDFName(#"\\spfs1\stone\Long Term Share\db_objects\JobBookViewer\select_mold.pdf");
try
{
if (!String.IsNullOrEmpty(Page.Request.QueryString["MoldID"])) // if the string is not null
{
id = (Page.Request.QueryString["MoldID"]);
ListBox1.Items.Clear();
System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(#"\\spfs1\stone\mold_books\" + id.ToString());
System.IO.FileInfo[] Files = dinfo.GetFiles("*.pdf");
foreach (System.IO.FileInfo file in Files)
{
ListBox1.Items.Add(file.Name);
}
}
}
catch { }
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
file = fnFilePDFName(#"\\spfs1\stone\mold_books\" + Page.Request.QueryString["MoldID"] + #"\" + ListBox1.SelectedValue);
}
private string ModifyQueryStringValue(string p_Name, string p_NewValue)
{
var nameValues = System.Web.HttpUtility.ParseQueryString(Request.QueryString.ToString());
nameValues.Set(p_Name, p_NewValue);
string url = Request.Url.AbsolutePath;
string updatedQueryString = "?" + nameValues.ToString();
return url + updatedQueryString;
}
public string fnFilePDFName(string path)
{
string sfileContent;
Byte[] bytes = File.ReadAllBytes(path);
sfileContent = Convert.ToBase64String(bytes);
return sfileContent;
}
}
}

Related

delayed rediraction asp.net

so I have a login page and I'm trying to have it say "the user doesn't exist" and have it redirect you to the signup page immediately after showing this message, but my current code simply redirects you without displaying the message.
sorry if the message is unclear, its the first time i ever write anything in here:)
ulogin.html page:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="ulogin.aspx.cs" Inherits="User_ulogin" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style5 {
position: absolute;
top: 62px;
left: 53px;
z-index: 1;
}
.auto-style6 {
position: absolute;
top: 140px;
left: 56px;
z-index: 1;
}
.auto-style7 {
position: absolute;
top: 67px;
left: 279px;
z-index: 1;
width: 289px;
}
.auto-style8 {
position: absolute;
top: 141px;
left: 304px;
z-index: 1;
width: 295px;
}
.auto-style9 {
position: absolute;
top: 207px;
left: 219px;
z-index: 1;
}
.auto-style11 {
position: absolute;
top: 277px;
left: 10px;
z-index: 1;
width: 256px;
}
.auto-style12 {
position: absolute;
top: 16px;
left: 244px;
z-index: 1;
}
</style>
</head>
<body style="z-index: 1; width: 1490px; height: 16px; position: absolute; top: 0px; left: 0px">
<form id="form1" runat="server">
<div style="width: 1400px; margin: 0 auto;">
<asp:Label ID="Label2" runat="server" CssClass="auto-style5" Text="username:" Font-Size="18pt" Font-Bold="True"></asp:Label>
<asp:Label ID="Label3" runat="server" CssClass="auto-style6" Text="password:" Font-Size="18pt" Font-Bold="True"></asp:Label>
<asp:TextBox ID="txtuser" runat="server" CssClass="auto-style7" BorderColor="Black" OnTextChanged="txtuser_TextChanged"></asp:TextBox>
<asp:TextBox ID="txtpass" runat="server" CssClass="auto-style8" BorderColor="Black" OnTextChanged="txtpass_TextChanged"></asp:TextBox>
<asp:Button ID="Button1" runat="server" CssClass="auto-style9" OnClick="Button1_Click" Text="connect now" BackColor="Azure" Font-Size="16pt" BorderColor="Black" />
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="auto-style11" Font-Size="14pt" Font-Underline="True">lost your password? reset it now</asp:HyperLink>
**<asp:Label ID="lblsucc" runat="server" style="z-index: 1; left: 746px; top: 97px; position: absolute" Text="user dont exist" Visible="False"></asp:Label>**
<asp:Label ID="Label4" runat="server" CssClass="auto-style12" Font-Size="XX-Large" Text="Sign Now"></asp:Label>
</div>
</form>
</body>
</html>
ulogin.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class User_ulogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblsucc.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
users user = new users();
admin adn = new admin(txtuser.Text, txtpass.Text);
user.User_Name = txtuser.Text;
user.Pass = txtpass.Text;
if (user.login(user))
{
Session["user"] = txtuser.Text;
Response.Redirect("homepage.aspx");
}
else
{
lblsucc.Visible = true;
}
if(user.ifexist(user))
Response.Redirect("uregister.aspx");
}
protected void txtuser_TextChanged(object sender, EventArgs e)
{
}
protected void txtpass_TextChanged(object sender, EventArgs e)
{
}
protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
{
Response.Redirect("homepage.aspx");
}
}
'''
the relevant classes codes:
''' public bool login(users us)
{
DataSet dsUser = new DataSet();
string stuser = "SELECT tblUsers.User_Name, tblUsers.User_Password FROM tblUsers WHERE(((tblUsers.User_Password) = '" + us.user_Name + "')AND((tblUsers.User_Password) = '" + us.Pass + "')); ";
dsUser = sql.chkData(stuser);
if (dsUser.Tables[0].Rows.Count > 0)
{
return true;
}
else return false;
}'''
'''public bool ifexist(users user)
{
bool chk = false;
DataSet dsUser = new DataSet();
string stuser = "SELECT tblUsers.User_Name FROM tblUsers WHERE(((tblUsers.User_Name) ='" + user.User_Name + "'));";
dsUser = sql.chkData(stuser);
if (dsUser.Tables[0].Rows.Count > 0)
chk = true;
return chk;
}'''

HTML select element firing an onclick event in C#

In my Visual Studio project (ASP.NET Web Forms), I have a <select> in the HTML file:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="clientes.aspx.cs" Inherits="Leo.clientes" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="topnav">
Dashboard
<a class="active" href="/clientes">Clientes</a>
Despesas
</div>
<div style="padding-left:16px">
<label for="cars">Cliente:</label>
<select name="listaClientes" id="listaClientes" onserverchange="escolherCliente" runat="server">
</select>
</div>
</form>
</body>
</html>
In my cs file, I have a function called escolherCliente. This function is called by using the onserverchange event above.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
namespace Leo
{
public partial class clientes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string mycon = "server = localhost; Uid = Leo; password = password; persistsecurityinfo = True; database = db; SslMode = none";
MySqlConnection con = new MySqlConnection(mycon);
MySqlCommand cmd = null;
try
{
cmd = new MySqlCommand("select nome from cliente;", con);
con.Open();
MySqlDataReader leitor = cmd.ExecuteReader();
while(leitor.Read())
{
listaClientes.Items.Add(new ListItem(leitor.GetString(0)));
}
con.Close();
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "')</script>");
con.Close();
}
}
protected void escolherCliente(object sender, EventArgs e)
{
Response.Write("<script>alert('fdasfdsfsdfasfsafds')</script>");
}
}
}
The problem is that the function is not getting called. I change the selected <option> in the <select>, and nothing happens.
I already tried using onchange instead of onserverchange, and it also didn't work.
What should I do?

Dynamic grid on ASP.NET

I here to seek an advice ,what is the best approach.
here is the scenario.
I am building my project ASP.NET (C#)
I need to add an dynamic drop down box based on that two other text box related to drop down.
for example :
I have a button called "ADD LANDSCAPE", every time this triggered, i have to create an dynamic drop down "ddlLandscap" and two text boxes so the user can enter landscape value for each text box.
Can you guys please advise what's the best approach
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="CS1.aspx.cs" Inherits="workout.CS1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="../jquery/jquery-ui.css" rel="stylesheet" />
<script src="../jquery/jquery-1.12.0.js"></script>
<script src="../jquery/jquery-ui.js"></script>
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}
.table {
border: 1px solid #ccc;
border-collapse: collapse;
}
.table th {
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
.table th, .table td {
padding: 5px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvCustomers1" CssClass="table" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Slno" ItemStyle-Width="50px" ItemStyle-CssClass="Slno">
<ItemTemplate>
<%# Eval("Slno") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" ItemStyle-Width="150px" ItemStyle-CssClass="Name">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country" ItemStyle-Width="150px" ItemStyle-CssClass="Country">
<ItemTemplate>
<%# Eval("Country")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Option">
<ItemTemplate>
<asp:Button ID="lnkDelete" runat="server" Text="Delete" OnClientClick="Confirmationbox(this);" />
<asp:Button ID="btn_update" runat="server" Text="Update" OnClientClick="updateable(this);" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button ID="btnNewUser" runat="server" Text="Add" OnClientClick="return false;" />
<asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Submit" OnClientClick="formatData()" />
<br />
<div id="dialog-form" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 150px">Name:<br />
<asp:TextBox ID="txtName" runat="server" Width="140" Text="" />
</td>
<td style="width: 150px">Country:<br />
<asp:TextBox ID="txtCountry" runat="server" Width="140" Text="" />
</td>
</tr>
</table>
</div>
<div id="dialog-form-edit" title="Edit user">
<p class="validateTips">All form fields are required.</p>
<asp:HiddenField ID="hdslno" runat="server" Value="" />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 150px">Name:<br />
<asp:TextBox ID="TextBox1" runat="server" Width="140" Text="" />
</td>
<td style="width: 150px">Country:<br />
<asp:TextBox ID="TextBox2" runat="server" Width="140" Text="" />
</td>
</tr>
</table>
</div>
<br />
<script type="text/javascript">
var dialog,editDialog;
function formatData() {
var formatdata = "";
$( '#gvCustomers1 tr:gt(0)' ).each( function () {
$( this ).find( 'td' ).each( function () {
if ( $( this ).hasClass( "Slno" ) || $( this ).hasClass( "Name" ) || $( this ).hasClass( "Country" ) ) {
formatdata += $( this ).html() + "|";
}
} );
formatdata += ",";
} );
alert( formatdata );
return false;
}
$(function () {
dialog = $("#dialog-form").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Create an account": AddRow,
Cancel: function () {
dialog.dialog("close");
}
},
close: function () {
$("#txtName").val("");
},
open: function () {
var nr = $('#dialog-form').data('param');
if (nr) {
$("#txtName").val(nr);
} else {
$("#txtName").val("");
}
}
});
editDialog = $("#dialog-form-edit").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Create an account": UpdateRow,
Cancel: function () {
editDialog.dialog("close");
}
},
close: function () {
$("#txtName").val("");
},
open: function () {
var nr = $('#dialog-form-edit').data('param');
console.log(nr);
$( "#hdslno" ).val( nr.slno );
$("#TextBox1").val(nr.name);
$("#TextBox2").val(nr.country);
}
});
});
$("#btnNewUser").button().on("click", function () {
dialog.dialog("open");
});
function Confirmationbox(obj) {
if (confirm("Do you want to delete this Customer?")) {
var row = $(obj).closest("tr");
row.remove();
}
return true;
}
function updateable(obj) {
var row = $(obj).closest("tr");
var slno = $(row).find("td").eq(0).html();
var name = $(row).find("td").eq(1).html();
var country = $(row).find("td").eq(2).html();
try {
var json = {
slno: slno,
name: name,
country: country
};
editDialog.data('param', json).dialog("open");
event.preventDefault();
} catch (e) {
alert(e);
}
return false;
}
function UpdateRow() {
var slno = $( "#hdslno" ).val();
var m_Name = $( "#TextBox1" ).val();
var m_Country = $( "#TextBox2" ).val();
var row = null;
$( '#gvCustomers1 tr:gt(0)' ).each( function () {
$( this ).find( 'td' ).each( function () {
if ( $( this ).hasClass( "Slno" ) && $( this ).html() == slno ) {
row = $( this ).closest( "tr" );
}
} )
} );
if ( row ) {
$( row ).find( "td" ).eq( 1 ).html( m_Name );
$( row ).find( "td" ).eq( 2 ).html( m_Country );
}
editDialog.dialog( "close" );
return false;
}
function AddRow() {
//Reference the GridView.
var gridView = document.getElementById("<%=gvCustomers1.ClientID %>");
//Reference the TBODY tag.
var tbody = gridView.getElementsByTagName("tbody")[0];
//Reference the first row.
var row = tbody.getElementsByTagName("tr")[1];
//Check if row is dummy, if yes then remove.
if (row.getElementsByTagName("td")[0].innerHTML.replace(/\s/g, '') == "") {
tbody.removeChild(row);
}
//Clone the reference first row.
row = row.cloneNode(true);
var legnth = gridView.rows.length;
SetValue1(row, 0, "Slno", legnth);
//Add the Name value to first cell.
var txtName = document.getElementById("<%=txtName.ClientID %>");
SetValue(row, 1, "name", txtName);
//Add the Country value to second cell.
var txtCountry = document.getElementById("<%=txtCountry.ClientID %>");
SetValue(row, 2, "country", txtCountry);
//Add the row to the GridView.
tbody.appendChild(row);
dialog.dialog("close");
return false;
}
function SetValue(row, index, name, textbox) {
row.cells[index].innerHTML = textbox.value;
textbox.value = "";
}
function SetValue1(row, index, name,leng) {
row.cells[index].innerHTML = leng;
}
</script>
<asp:HiddenField ID="hdTableValues" runat="server" Value="" />
</form>
</body>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace workout
{
public partial class CS1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
DataTable dt = new DataTable();
string query = "SELECT '' Slno, Name, Country FROM dd_Detils";
string constr = "Data Source=localhost;Initial Catalog=DataBase;User ID=sa;Password=globalfocus";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.SelectCommand = cmd;
sda.Fill(dt);
}
}
}
if (dt.Rows.Count == 0)
{
//If no records then add a dummy row.
dt.Rows.Add();
}
gvCustomers1.DataSource = dt;
gvCustomers1.DataBind();
}
protected void Submit(object sender, EventArgs e)
{
int cnt = gvCustomers1.Rows.Count;
if (!string.IsNullOrEmpty(Request.Form["name"]) && !string.IsNullOrEmpty(Request.Form["country"]))
{
//Fetch the Hidden Field values from the Request.Form collection.
string[] names = Request.Form["name"].Split(',');
string[] countries = Request.Form["country"].Split(',');
//Loop through the values and insert into database table.
for (int i = 0; i < names.Length; i++)
{
string constr = "Data Source=localhost;Initial Catalog=Database;User ID=sa;Password=globalfocus";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO dd_Detils VALUES(#Name, #Country)"))
{
cmd.Parameters.AddWithValue("#Name", names[i]);
cmd.Parameters.AddWithValue("#Country", countries[i]);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
//Refresh the page to load GridView with records from database table.
Response.Redirect(Request.Url.AbsoluteUri);
}
}
}
}

Adding polylines to Bing maps programmatically

I have routes names in my dropdownlist and arrays with lat/log (polylines) with correspondence by event. How to send this lat/log from code behind to javascript?
<head>
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap() {
// Initialize the map
var mapOptions = {
credentials: "xxxx",
center: new Microsoft.Maps.Location( 9.74, 2.425),
mapTypeId: Microsoft.Maps.MapTypeId.road,
zoom: 13,
showScalebar: false
}
var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions);
var lineVertices = new Array(new Microsoft.Maps.Location(<%#new pts%>));
var line = new Microsoft.Maps.Polyline(lineVertices);
map.entities.push(line);
}
</script>
<style type="text/css">
#form1
{
width: 480px;
}
</style>
<body onload="GetMap();" style="height: 18px; width: 480px">
<form id="form1" runat="server">
<div id='listDiv' style="width:480px; height:30px" >
<asp:DropDownList ID="listPicker" runat="server" Height="25px" Width="218px"
onselectedindexchanged="listPicker_SelectedIndexChanged">
</asp:DropDownList>
</div>
<div id='mapDiv' style="position:absolute; width:480px; height:740px; top: 38px; ">
</div>
</form>
protected void listPicker_SelectedIndexChanged(object sender, EventArgs e)
{
if (listPicker.SelectedIndex == 1)
{
pts = new double[,] {
{ 9.6990549318566, 2.4374476373222},
{ 9.6991218770296, 2.4379291260322},
{ 9.6994116428257, 2.4376508334228},
{ 9.6995069262757, 2.4356545805958},
{ 9.6999728977379, 2.4356384873417},
{ 9.6999845469968, 2.4326612353352},
{ 9.7056459228308, 2.432768526198},
{ 9.7088142924775, 2.4295498753801},
{ 9.7228377868168, 2.4293138409868},
{ 9.7228098349562, 2.4276401425615}};
}else{...}
}
There is a way to send this points to js?
You can try
Dim oGeocodeList As New List(Of [String])()
oGeocodeList.Add(" '37.968002524107035, 23.702445030212402' ")
oGeocodeList.Add(" '37.969, 23.705445030212402' ")
oGeocodeList.Add(" '37.97, 23.709445030212402' ")
Dim geocodevalues = String.Join(",", oGeocodeList.ToArray())
ClientScript.RegisterArrayDeclaration("locationList", geocodevalues)
and in javacrtipt
var locationList;
I am sorry for the vb code.

How to display a dynamically created DIV next to another?

I am creating a page that will display log files on a page dynamically as they are created. Here is my front end:
<div id="container">
<asp:UpdatePanel UpdateMode="Conditional" runat="server" ID="ServerUpdates">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
Here is my css:
#container {
width:100%;
display: inline-block;
height:100%;
}
.textboxStatus
{
/*background-image:url('http://placehold.it/15/15');*/
background-repeat:no-repeat;
/* background-position:3px 3px;*/
border:solid 1px black;
padding:20px;
width:600px;
height:500px;
float:left;
clear:left;
/*position:relative;*/
}
/*.textbox input
{
border:none;
background:transparent;
width:100%;
outline: none;
}*/
.textboxURL
{
/*background-image:url('http://placehold.it/15/15');*/
background-repeat:no-repeat;
/* background-position:3px 3px;*/
border:solid 1px black;
padding:20px;
width:575px;
height:475px;
float:right;
/*clear: right;
position:relative;*/
display:inline;
}
Here is my code behind:
protected void CreateDiv(object sender, EventArgs e)
{
string path = #"\\server\d$\websites\Updates\Product\Production\Logs";
//int rowCount = 0;
DirectoryInfo dir = new DirectoryInfo(path);
List<FileInfo> FileList = dir.GetFiles().ToList();
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("<asp:GridView runat='server' ID='Grid' AutoGenerateColumns='false'>"));
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("<Columns>"));
foreach (FileInfo file in FileList)
{
StreamReader sr = new StreamReader(new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
// string[] findStatus = System.IO.Directory.Exists(path, "codepush.log.*", System.IO.SearchOption.TopDirectoryOnly);
// string[] findURL = System.IO.Directory.GetFiles(path, "sql.output.log.*", System.IO.SearchOption.TopDirectoryOnly);
bool findStatus = (file.Name.Contains("codepush.log.")) ? true : false;//File.Exists(Path.Combine(path, ".txt"));
bool findURL = (file.Name.Contains("sql.output.")) ? true : false;
if (findStatus == true)
{
//ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<br /><div class=\"statusLog\"><asp:TextBox runat=\"server\" id=\"tbStatus{0}\"/> </div><div class=\"urlLog\"></div>", count)));
//(TextBox)ServerUpdates.ContentTemplateContainer.FindControl("tbStatus" + count.ToString());
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<asp:BoundField Datafield={0} /><div class='textboxStatus'>", rowCount)));
TextBox txt = new TextBox();
txt.TextMode = TextBoxMode.MultiLine;
txt.Wrap = false;
txt.Width = 600;
txt.Height = 500;
while (!sr.EndOfStream)
txt.Text = txt.Text + sr.ReadLine() + "\r\n";
//Panel txt = new Panel();
//txt.ScrollBars = ScrollBars.Vertical;
//txt.Wrap = true;
ServerUpdates.ContentTemplateContainer.Controls.Add(txt);
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("</Columns>"));
}
if (findURL == true)
{
//ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<br /><div class=\"statusLog\"><asp:TextBox runat=\"server\" id=\"tbStatus{0}\"/> </div><div class=\"urlLog\"></div>", count)));
//(TextBox)ServerUpdates.ContentTemplateContainer.FindControl("tbStatus" + count.ToString());
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("<Columns>"));
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<asp:BoundField Datafield={0} /><div class='textboxURL'>", rowCount)));
TextBox txt = new TextBox();
txt.TextMode = TextBoxMode.MultiLine;
txt.Wrap = false;
txt.Width = 575;
txt.Height = 475;
while (!sr.EndOfStream)
txt.Text = txt.Text + sr.ReadLine() + "\r\n";
//Panel txt = new Panel();
//txt.ScrollBars = ScrollBars.Vertical;
//txt.Wrap = true;
ServerUpdates.ContentTemplateContainer.Controls.Add(txt);
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("</Columns>"));
}
//rowCount++;
}
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("</asp:GridView>"));
}
My issue is that it is not displaying the URL div next to the first Status div and so fourth. The URL div displays last.
I need it to display the URL div next to the Status div for each div (file).
I have been trying GridView so any suggestions would be helpful.
I am not sure I understand the problem, but to your issue " it is not displaying the URL div next to the first Status div and so fourth. The URL div displays last," I recommend the following:
<div class="row">
<div class="textboxStatus">
</div>
<div class="textboxURL">
</div>
</div>
Apply float: left; to both textboxStatus and textboxURL. I understand, this is dynamically generated, but instead, why not AJAX to fetch the content and then simply fill it?
You can easily use AJAX with webforms like so:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
In your ".textboxStatus" css-class you have defined a "float:left" and are clearing the float at the same time with "clear:left".
Remove both attributes and in ".textboxURL" replace "float:right" with "float:left" and you should be fine.
first we will define the main div or body in which other will be contained for that div the style will be
#maindiv{
width: 100%;
font-size: 12px;
overflow: hidden;
background: #ccc
}
in your case it will be "container"
now when you are adding the divs as
then first div style will be
#leftdiv {
float: left;
width: 33%;
background-color: #bbb;
}
after that set the width of each div and put the width to the style of that d
#nextdiv {
float: left;
background-color: #eee;
width: 33%;
}
and so on..
You should generate a <TABLE> with one line <TR> and multiple columns <td> instead of generating an Asp.net Gridview control by Literal controls.
Remember to write Html tags when you use Literal controls
Example of final html:
<Table>
<tr>
<td>First div inside</td>
<td>Second div inside</td>
...
</tr>
</Table>

Categories