Set value of TextBox after function execution asp.net - asp.net

I try to make a site with a asp.net web application, but I can't continue because, I can not set the value of TextBox to "finish" after the execution of a function file download.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox1.Text = "start";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=print_ordre.pdf");
Response.TransmitFile(Server.MapPath("~/print_ordre.pdf"));
//Response.End();
TextBox1.Text = "finish";
}
I await your help ...

Related

asp.net: Create Handles clause for control class

Is there a way that I force all TextBoxes (as an example) .. on an asp.net form, to go through the same routine, during a "postback" event or onchange event?
Here is example code.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
textBox1.TextChanged += new EventHandler(textBox_TextChanged);
textBox2.TextChanged += new EventHandler(textBox_TextChanged);
}
}
protected void textBox_TextChanged(object sender, EventArgs e)
{
}

How to browse & display excel sheet in web browser using asp.net?

i want to browse the excel input file & display it on web browser & it must be editable on web browser,
i am using C# asp.net for coding. Any help would be gr8. Thnks in advance.
I think the options you have are HTML tables or Google Spreadsheets / Microsoft Excel Online.
For more info:
http://www.labnol.org/software/embed-tables-spreadsheet-data-in-websites/7435/
In the webform:
Code behind:
protected void UploadFile(object sender, EventArgs e)
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
Response.Redirect(Request.Url.AbsoluteUri);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] filePaths = Directory.GetFiles(Server.MapPath("~/Uploads/"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
Fileddl.Items.Add(new ListItem(Path.GetFileName(filePath), Path.GetFileName(filePath)));
}
}
}
protected void OpenFile(object sender, EventArgs e)
{
string filePath = Fileddl.SelectedItem.Value;
Myframe.Visible = true;
Myframe.Attributes.Add("src", "https://view.officeapps.live.com/op/embed.aspx?src=https://www.yoursite.com/Uploads/" + Path.GetFileName(filePath));
}
protected void DownloadFile(object sender, EventArgs e)
{
string filePath = Fileddl.SelectedItem.Value;
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=https://www.yoursite.com/Uploads/" + Path.GetFileName(filePath));
Response.WriteFile(filePath);
Response.End();
}
protected void DeleteFile(object sender, EventArgs e)
{
string filePath = Fileddl.SelectedItem.Value;
File.Delete(filePath);
Response.Redirect(Request.Url.AbsoluteUri);
}

ASP.NET Session State - Works In Firefox & IE8, not in Chrome

I am trying to pass four items using session state as follows:
protected void createFirstNameSessionVariable(object sender, EventArgs e)
{
Session["FirstName"] = firstName.Value;
Session.Timeout = 60;
TextBox1.Text = Session["FirstName"].ToString();
}
protected void createLastNameSessionVariable(object sender, EventArgs e)
{
Session["LastName"] = lastName.Value;
Session.Timeout = 60;
TextBox2.Text += Session["LastName"].ToString();
}
protected void createIdSessionVariable(object sender, EventArgs e)
{
Session["FacebookId"] = facebookId.Value;
Session.Timeout = 60;
TextBox3.Text += Session["FacebookId"].ToString();
}
protected void createEmailSessionVariable(object sender, EventArgs e)
{
Session["Email"] = email.Value;
Session.Timeout = 60;
TextBox4.Text += Session["Email"].ToString();
}
In Firefox and IE8, I can get them on another page using the following:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["FacebookId"] != null)
{
name = Session["FacebookId"].ToString();
studentButton.Text = name;
}
else
{
studentButton.Text = "fail";
}
}
In Chrome, however, the button label is set to fail because the session variable has a null value on the receiving end.
On IIS 7.0 Manager, the session state is currently set to "In Process"
Mode: Use Cookies
Name: ASP.NET_SessionId
Time out: 20 mins
Use hosting identity for impersonation is checked.
Thanks for your help.
Make sure that you have allowed cookies in Chrome.

Drop down selected index changed on page load

I have a drop down box that populates textbox values based on its value. It fires when it is changed but on pageload it doesnt fire. How do I get it to fire on page load?
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox3.Text = DropDownList1.SelectedValue;
TextBox12.Text = DropDownList1.SelectedValue;
TextBox21.Text = DropDownList1.SelectedValue;
//etc
Tim Schmelter's comment is right on the money.
// Wire up to the page load event
protected void Page_Load(object sender, System.EventArgs e)
{
updateTextBoxes();
}
// Wire up to the select index-changed event
protected void DropDownList1_SelectIndexChanged( object sender, EventArgs e )
{
updateTextBoxes();
}
// your workhorse method
protected void updateTextBoxes()
{
TextBox3.Text = DropDownList1.SelectedValue;
TextBox12.Text = DropDownList1.SelectedValue;
TextBox21.Text = DropDownList1.SelectedValue;
// etc.
}
It won't be called automatically at page load, you have to call it "manually":
void Page_Load(object sender, System.EventArgs e) {
// ....
DropDownList1_SelectedIndexChanged(DropDownList1, e);
}
SelectedIndexChanged fires in response to a user-driven change. Move the assignment logic to another method and call it manually from Page_Load and also from your event handler.

Linking database column to dropdown control in ASP.Net

I am using c# with asp.net and SQL Server 2005 as backend. I want to use dropdown list control in a form to populate a textbox. The dropdown control is linked to a column in the database. How can I code this in c#?
Do you mean this
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.datasource = list;
DropDownList1.datBind();
}
protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.SelectedValue;
}
Or this
protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e)
{
TextBox t = new TextBox();
t.Text = DropDownList1.SelectedValue;
body.InnerHtml.add(t);
}

Resources