I am back to C# after roaming around with other languages.
I am facing an issue after the file has been moved to the 2 locations successfully.
Issue:
I can't see the Thumbnail uploaded.
The issue is on the CS code when listing the images exactly here I assume, I don't know how to call the file to read, using which path...
string fileName = Path.GetFileName(filePath);
files.Add(new ListItem(fileName, "C:/Image_folder/" + fileName));
Any help is welcome
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" />
<hr />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" ShowHeader="false">
<Columns>
<asp:BoundField DataField="Text" />
<asp:ImageField DataImageUrlField="Value" ControlStyle-Height="100" ControlStyle-Width="100" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
CS
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Collections.Generic;
public partial class CS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] filePaths = Directory.GetFiles("C:\\Image_folder\\");
List <ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
string fileName = Path.GetFileName(filePath);
files.Add(new ListItem(fileName, "C:/Image_folder/" + fileName));
}
GridView1.DataSource = files;
GridView1.DataBind();
}
}
protected void Upload(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs("C:\\Image_folder\\" + fileName);
File.Copy("C:\\Image_folder\\" + fileName, "\\\\192.168.1.1\\shared_image_folder\\" + fileName, true);
Response.Redirect(Request.Url.AbsoluteUri);
}
}
}
SOURCE FROM THE GRID
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="./CS.aspx" id="form1" enctype="multipart/form-data">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTIwMTcxNDg1MzIPZBYCAgMPFgIeB2VuY3R5cGUFE211bHRpcGFydC9mb3JtLWRhdGEWAgIFDzwrABEDAA8WBB4LXyFEYXRhQm91bmRnHgtfIUl0ZW1Db3VudAIDZAEQFgAWABYADBQrAAAWAmYPZBYKZg8PFgIeB1Zpc2libGVoZGQCAQ9kFgRmDw8WAh4EVGV4dAUZMjg0NHgxNjAwLWJhY2tncm91bmRzLnBuZ2RkAgEPZBYEZg8PFgIeDUFsdGVybmF0ZVRleHRlZGQCAQ8PFgIfA2hkZAICD2QWBGYPDxYCHwQFFWJhY2tncm91bmRfc2t5ZWVlLmpwZ2RkAgEPZBYEZg8PFgIfBWVkZAIBDw8WAh8DaGRkAgMPZBYEZg8PFgIfBAUWYmFja2dyb3VuZF9za3llZWVlLmpwZ2RkAgEPZBYEZg8PFgIfBWVkZAIBDw8WAh8DaGRkAgQPDxYCHwNoZGQYAQUJR3JpZFZpZXcxDzwrAAwBCAIBZPplLAL2cXZ3yOS32KPXgASprFrPV/4fflzzREt6LxQN" />
</div>
<input type="file" name="FileUpload1" id="FileUpload1" />
<input type="submit" name="btnUpload" value="Upload" id="btnUpload" />
<hr />
<div>
<table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">
<tr>
<td>2844x1600-backgrounds.png</td><td><img src="" style="height:100px;width:100px;" /></td>
</tr><tr>
<td>background_skyeee.jpg</td><td><img src="" style="height:100px;width:100px;" /></td>
</tr><tr>
<td>background_skyeeee.jpg</td><td><img src="" style="height:100px;width:100px;" /></td>
</tr>
</table>
</div>
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="17CECB09" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAJ1o9wC/FD3hrc5v52GfoAN5vhDofrSSRcWtmHPtJVt4Nr3LRFm+giVnIqfnqj9kuxQ47Dj1gv1HmdZrTjLiXPV" />
</div></form>
<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
{"appName":"Chrome","requestId":"336b94aad34847b39a4af20e67138af9"}
</script>
<script type="text/javascript" src="http://localhost:60480/011c96c87fbd421fa3485ec4702d5c1b/browserLink" async="async"></script>
<!-- End Browser Link -->
</body>
</html>
The problem is you are using an absolute path for the images. You have to use a relative path to your application. For this you can copy the original folder to your project folder. It is not necessary to include this folder to your project. Then just change the code like below
string[] filePaths = Directory.GetFiles(Server.MapPath("~/Image_folder"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
string fileName = Path.GetFileName(filePath);
files.Add(new ListItem(fileName, "~/Image_folder/" + fileName));
}
GridView1.DataSource = files;
GridView1.DataBind();
You have to change your upload code as well to use the folder in your project. Use the following code
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Image_folder/") + fileName);
File.Copy(Server.MapPath("~/Image_folder/") + fileName, "\\\\192.168.1.1\\shared_image_folder\\" + fileName, true);
Related
I am currently writing an addition to a website that I made for work. It generates a PDF from an HTML template and then serves it to the browser so that it can be printed off.
I created a small test that works perfectly. The problem I am running into is when I coded a more complete test, nothing happens when I click the generate button. In the first page when the page loads the PDF is created and shows in the browser. On the second page I get nothing, and no error message which makes troubleshooting this difficult. The code is almost identical between the two pages, so I am really confused as to what is happening.
I will post both versions of my code. Hopefully you guys can figure out what is happening.
Working Page
<%# Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string filePath = Server.MapPath("/test.pdf");
string html = "<h1>Hello World</h1>";
PdfSharp.Pdf.PdfDocument my_pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.Letter);
my_pdf.Save(filePath);
byte[] docStream = System.IO.File.ReadAllBytes(filePath);
Response.ClearContent();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=test.pdf");
Response.AddHeader("Content-Length", docStream.GetLength(0).ToString());
Response.BinaryWrite(docStream);
Response.End();
System.IO.File.Delete(filePath);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Non Working Page
<%# Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
frmMain.Style.Add(HtmlTextWriterStyle.Width, "900px");
frmMain.Style.Add(HtmlTextWriterStyle.MarginLeft, "auto");
frmMain.Style.Add(HtmlTextWriterStyle.MarginRight, "auto");
tblForm.Style.Add(HtmlTextWriterStyle.MarginRight, "auto");
tblForm.Style.Add(HtmlTextWriterStyle.MarginLeft, "auto");
}
protected void generate_pdf(object sender, EventArgs e)
{
string html_page = System.IO.File.ReadAllText(Server.MapPath("/nice_letter.html"));
string filePath = Server.MapPath($"/{RandomString(10, true)}.pdf");
html_page = html_page.Replace("{{letter_date}}", txtLetterDate.Text);
html_page = html_page.Replace("{{recipient_name}}", txtRecipientName.Text);
html_page = html_page.Replace("{{patient_name}}", txtPatientName.Text);
html_page = html_page.Replace("{{appointment_date}}", txtAppointmentDate.Text);
PdfSharp.Pdf.PdfDocument my_pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html_page, PdfSharp.PageSize.Letter);
my_pdf.Save(filePath);
byte[] docStream = System.IO.File.ReadAllBytes(filePath);
Response.ClearContent();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=letter.pdf");
Response.AddHeader("Content-Length", docStream.GetLength(0).ToString());
Response.BinaryWrite(docStream);
Response.End();
System.IO.File.Delete(filePath);
}
public string RandomString(int size, bool lowerCase = false)
{
Random _random = new Random();
var builder = new StringBuilder(size);
char offset = lowerCase ? 'a' : 'A';
const int lettersOffset = 26;
for (var i = 0; i < size; i++)
{
var #char = (char)_random.Next(offset, offset + lettersOffset);
builder.Append(#char);
}
return lowerCase ? builder.ToString().ToLower() : builder.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="frmMain" runat="server">
<center><h1>Nice Letter</h1></center>
<asp:ScriptManager ID="smMain" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="upMain" runat="server">
<ContentTemplate>
<table id="tblForm" runat="server">
<tr>
<td><asp:Label ID="lblLetterDate" Text="Letter Date: " runat="server"></asp:Label></td>
<td><asp:TextBox ID="txtLetterDate" Width="150" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="lblRecipientName" Text="Recipient: " runat="server"></asp:Label></td>
<td><asp:TextBox ID="txtRecipientName" Width="300" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="lblPatientName" Text="Patient Name: " runat="server"></asp:Label></td>
<td><asp:TextBox ID="txtPatientName" Width="300" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="lblAppointmentDate" Text="Appointment Date: " runat="server"></asp:Label></td>
<td><asp:TextBox ID="txtAppointmentDate" Width="150" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="cmdCreatePDF" runat="server" Text="Create PDF" OnClick="generate_pdf" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
I figured out the problem. Apparently it was because I was doing an ajax request via the update panels. It works fine without the ajax.
I'm trying to update text in an SQL database using a text box. This is for an admin to overwrite the data in the database. Having trouble declaring one of the variables.
The itemnametext doesn't exist in the current context.
Code for itemediting page:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="admin_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>elmtree - Admin</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" />
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="../styles/mylist.css" />
</head>
<body>
<form id="form1" runat="server">
<img src="images/ELleft.png" style="width:226px; height:52px; margin-top: 3px; margin-left: 17px; text-align: justify; float: none;"/></a></li>
<div class="container">
<h1> Item Edit </h1> </div>
<div class="container">
<div class="form-group">
<label class="col-sm-2 control-label">Item name: </label>
<div class="col-md-4">
<asp:TextBox ID="itemnameedit" runat="server" Text="" CssClass="form-control">
</asp:TextBox>
</div>
<div class="pull-right">
<asp:Button CssClass="btn btn-primary btn-lg" ID="updatebutton" role="button" runat="server" Text="save" OnClick="updatebutton_Click" />
</div>
</div>
</div>
</form>
</body>
</html>
Code for itemediting.aspx.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class admin_itemediting : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{
int row = 0;
if (Request.QueryString["itemID"] != null){
row = int.Parse(Request.QueryString["itemID"]);
}
else{
Response.Redirect("itemedit.aspx");
}
string connectionString = WebConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
string query = "SELECT * FROM reports WHERE ID=#rowid";
SqlCommand myCommand = new SqlCommand(query, myConnection);
myCommand.Parameters.AddWithValue("#rowid", row);
SqlDataReader rdr = myCommand.ExecuteReader();
while (rdr.Read())
{
string myname = rdr["itemname"].ToString();
itemnametext.Text = myname;
}
}
protected void updatebutton_Click(object sender, EventArgs e){
string connectionString = WebConfigurationManager.ConnectionStrings ["ConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
string itemnametextupdate = itemnametext.Text;
string query = "UPDATE reports SET itemname = #itemnewname";
}
}
}
Your textbox name is itemnameedit so itemnametext is not found
<asp:TextBox ID="itemnametext" runat="server" Text="" CssClass="form-control"></asp:TextBox>
EDIT: Your aspx page is Default and you are posting code for itemediting.aspx.cs.Post the code for itemediting.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="admin_Default" %>
Just change ID of your texbox from itemnameedit to itemnametext
Update: change your reference here to match the codefile and codefile class. I dont think you have right reference, so codefile class admin_itemediting don't know any of your control in the aspx file.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="itemediting.aspx.cs" Inherits="admin_itemediting" %>
I have displayed images in a grid view. But I don't understand how to display YouTube video in a grid-view?
Add a template column with literal control in it.
on itemdatabound fill the literal with the embed code of the YouTube video
Example:
((Literal)e.Item.FindControl("litvideo")).Text = "<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/r6BHyv6nkAs\" frameborder=\"0\" allowfullscreen></iframe>";
<asp:TemplateField ControlStyle-CssClass="Row" HeaderText="YouTube Video">
<ItemTemplate>
<asp:Label ID="lblYTVideoURL" runat="server" Text=<%# Eval("YTVideoUrl") %>></asp:Label>
</ItemTemplate>
<ControlStyle CssClass="Row"></ControlStyle>
</asp:TemplateField>
Then from the code behind:
protected void grvYoutubeVideo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl = (Label)e.Row.Cells[0].Controls[1];
if (lbl.Text != "")
{
//string YTVideoURL = lbl.Text; //"http://www.youtube.com/v/AyPzM5WK8ys";
//string OBJYTVideo = "<object width=\"150\" height=\"150\">";
//OBJYTVideo += "<param name=\"movie\" value=\"" + YTVideoURL + "\"></param>";
//OBJYTVideo += "<param name=\"allowscriptaccess\" value=\"always\"></param>";
//OBJYTVideo += "<embed src=\"" + YTVideoURL + "\" type=\"application/x-shockwave-flash\"";
//OBJYTVideo += "allowscriptaccess=\"always\" width=\"100%\" height=\"100%\"></embed></object>";
//lbl.Text = OBJYTVideo;
}
}
}
try some thing like this, you can put all this in .html and open. After you will easy add this to asp.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<object width="425" height="355">
<param name="movie" value="http://www.youtube.com/v/sSe_RmPlOLM" />
<param name="wmode" value="transparent" />
<embed src="http://www.youtube.com/v/sSe_RmPlOLM" type="application/x- shockwave-flash"
wmode="transparent" width="425" height="355" />
</object>
</div>
</form>
</body>
</html>
<asp:TemplateField HeaderText="Video">
<ItemTemplate>
<iframe id="video" width="420" height="250" frameborder="0" allowfullscreen src='<%# "http://www.youtube.com/embed/" + Eval("VideoURL").ToString().Split(new string[] { "v=" }, StringSplitOptions.None)[1] %>' frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
For those who worked with bootstrap, knows it does not support input type = file, so I hide the asp:fileupload using jQuery (after document ready), and have and for the solution (as you can see from the code
<script type="text/javascript">
$(document).ready(function ()
{
$('#columnSelect').change(function ()
{
getImportColumnOrder();
});
// change file upload style similiar to bootstrap style
//$('#uploader').hide();
$('#uploader').change(function ()
{
var val = $(this).val();
var file = val.split(/[\\/]/);
$('#file').val(file[file.length - 1]);
});
});
function getImportColumnOrder()
{
var order = '';
$('#selectOrer').val('');
$('select', $('#MappingTable')).each(function ()
{
order += $(this).prop('selectedIndex') + ',';
});
$('#selectOrder').val(order.substr(0, order.length - 1));
}
</script>
<div class="span12">
<asp:DropDownList ID="ddl_DBTableList" runat="server" CssClass="combobox" Style="display: inline">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Import_Test">Import_Test</asp:ListItem>
</asp:DropDownList>
<asp:FileUpload ID="uploader" runat="server" CssClass="btn" />
<div class="input-append" style="display: inline;">
<input id="file" class="input-medium" type="text" />
<a class="btn" onclick="$('input[id=uploader]').click();">Select File</a>
</div>
<p />
<div>
<asp:Button ID="btn_uplaod" runat="server" OnClick="doUpload" Text="Upload" CssClass="btn" />
</div>
<p />
<asp:Label ID="result" runat="server" ForeColor="Red"></asp:Label>
<p />
<asp:Label ID="data" runat="server" BackColor="#CCCCCC"></asp:Label>
<p />
<asp:Button ID="btn_import" runat="server" Text="Next" OnClick="doImport" OnClientClick="getImportColumnOrder();return true;" Visible="false" CssClass="btn btn-success" />
</div>
Steps are click on the "Select File", a file chooser popped up for file selection. After double clicked a file, the file location gets displayed in , and also the asp fileupload control.
In Chrome and FF, when I clicked btn_uplaod (button), it runs as supposed. In IE, it will clear the fileupload's content and does nothing (a client side action) and will not do any postback.
If this is a program problem, then maybe Chrome and FF will not run correctly. I'm suspecting is there anything that I need to add to make IE run as suppose to?
image after click upload (IE), (Browse link is cleared)
image after click upload (Chrome), (Run as supposed to)
thanks!
I've made a simple version for those of you who wants to try on Visual studio:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="postback_problem.aspx.cs" Inherits="postback_problem" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload ID="uploader" runat="server" CssClass="btn" /> <div> <input id="file" class="input-medium" type="text" /> <a onclick="$('input[id=uploader]').click();">Select File</a> </div> <p /> <div> <asp:Button ID="btn_uplaod" runat="server" OnClick="doUpload" Text="Upload" CssClass="btn" /> </div> <asp:Label ID="result" runat="server"></asp:Label> </div> </form> </body> </html>
and
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class postback_problem : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void doUpload(object sender, EventArgs e) { result.Text = "no problem!"; } }
I have a button in my asp.net web application. When i clicking the button it will hide the text box in the same webs application .
If is it possible that anyone help me its very useful
Thank you
If the button is an html button then you can use javascript to do this:
onclick of button call following js:
document.getElementById(textBoxId).style.display = "none";
or
document.getElementById(textBoxId).style.visibility = "hidden";
from code behind TextBoxId.Visible = false;
from Javascript document.getElementById('<%=TextBoxId.ClientId%>').style.dispaly="none";
You can do it with JQuery:
<script>
$("#myButton").click(function () {
$("#myTextBox").hide("slow");
});
</script>
This is what you are looking for:
HideTextBox.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="HideTextBox.aspx.cs" Inherits="HideTextFields" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<asp:Button ID="BtnHide" runat="server" onclick="Button1_Click"
Text="Hide TextBox" />
</div>
</form>
</body>
</html>
And the code behind file
HideTextBox.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class HideTextFields : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
foreach (Control c in form1.Controls)
{
if (c is TextBox)
c.Visible = false;
}
}
}