C#


I found a problem on ASP.net web Applications with read only text boxes not responding to the ‘viewsate’ property set, If you set the ‘readonly’ attribute to true. It will clear the readonly text box text up on postback.

<asp:TextBox ID=”companyTextBox” runat=”server” InvalidColor=”#ff0000″
MinimumPrefixLength=”3″ EnableViewState=”true” ReadOnly=”true”/>

The solution for avoiding clearance was to add the ‘readonly’ property at the run time on the event of each page load.

protected void Page_Load(object sender, EventArgs e)
{

this.companyTextBox.Attributes.Add(“ReadOnly”, “true”);

}

At the moment  I cannot understand how this happens. But will find out soon.

 

 

Advertisements

This is what I just found hope it is use full @ some point

System.Environment.Version.ToString();

Here is the code I used to open out look and set the to address and tittle and to do a attachment to that mail.

application.Visible = true;

book.SaveCopyAs(@”” + ConfigurationSettings.AppSettings[“Reports”] + “Course Schedules for “ + lblProviderName.Text + “.xls”);

Outlook.Application outlookApp = new Outlook.Application();

Outlook.MailItem message = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

message.Subject = “Course Schedules for “ + lblProviderName.Text + ” (“ + this.providerNumber + “) “;

message.Recipients.Add(“someone@email.com”);

message.Body = “”;

int attachmentLocation = 1;

message.Attachments.Add(“” + ConfigurationSettings.AppSettings[“Atachments”] + “Course Schedules for “ + lblProviderName.Text + “.xls”, Outlook.OlAttachmentType.olByValue,

attachmentLocation, “Course Schedules for “ + lblProviderName.Text + “.xls”);

message.Display(false);

Here is the code for creating a new Microsoft excel file open it and open a new sheet of it and to insert data from the data table to it and save the a copy of a application in your hard drive.

Excel.Application application;

Excel.Workbook book;

Excel.Worksheet sheet;

application = new Excel.ApplicationClass();

           

DataTable dt = new DataTable();

dt = dtCouseSchedule.Copy();

book = application.Workbooks.Add(Type.Missing);

sheet = (Excel.Worksheet)book.Worksheets[1];

sheet.Name = “SampleExcel”;

for (int i = 1; i <= dt.Rows.Count; i++)

   {

      for (int j = 1; j <= dt.Columns.Count; j++)

      {

   ((Excel.Range)sheet.Cells[i, j]).Value2 = dt.Rows[i – 1].ItemArray[j – 1].ToString();

 

       }

    }

application.Visible = true;

book.SaveCopyAs(@”” + ConfigurationSettings.AppSettings[“Reports”] + “Course Schedules for “ + lblProviderName.Text + “.xls”);

This is one of the most asked questions by a beginner in the C# devlopment

SqlConnection SqlCon = new SqlConnection(connectionString);

SqlCon.Open();

SqlCommand SqlCmd = new SqlCommand(cmdtxt, SqlCon);

SqlCmd.Dispose();

SqlCon.Close();