even when details view insert fails the application is sending an email - c#

I have an details view that is attached to a sql datasource. When a new workorder is inserted i am sending an email. Right now there is some issue with my program and the user is not able to insert the data from my application but the email still gets send assuming the data is inserted.
This is my Details View Inserted Method:
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
if (successfull == true && Page.IsValid && e.AffectedRows ==1)
{
//TextBox TextBoxWorkOrderNumber = (TextBox)(DetailsView1.FindControl("TextBox11"));
TextBox TextBoxRequestor = (TextBox)(DetailsView1.FindControl("TextBox3"));
TextBox TextBoxDate = (TextBox)(DetailsView1.FindControl("TextBox1"));
//TextBoxDate.Text = DateTime.Now.ToShortDateString();
TextBox TextBoxDepartment = (TextBox)(DetailsView1.FindControl("TextBox4"));
TextBox TextBoxCompletionDate = (TextBox)(DetailsView1.FindControl("TextBox16"));
TextBox TextBoxMachineDescription = (TextBox)(DetailsView1.FindControl("TextBox5"));
TextBox TextBoxMachineLocation = (TextBox)(DetailsView1.FindControl("TextBox6"));
TextBox TextBoxWorkRequired = (TextBox)(DetailsView1.FindControl("TextBox7"));
// DropDownList status = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
TextBox TextBoxStatus = (TextBox)(DetailsView1.FindControl("TextBox12"));
TextBoxStatus.Text = "Open";
DropDownList list = (DropDownList)(DetailsView1.FindControl("DropDownList1"));
TextBox9.Text = list.SelectedValue;
DropDownList lists = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
TextBox14.Text = lists.SelectedValue;
if (TextBoxRequestor.Text.Length <= 0)
{
TextBoxRequestor.Text = "Not Applicable";
}
if (TextBox14.Text.Length <= 0)
{
TextBoxDepartment.Text = "Not Provided";
}
if (TextBoxCompletionDate.Text.Length <= 0)
{
TextBoxCompletionDate.Text = "Not Provided";
}
if (TextBoxMachineDescription.Text.Length <= 0)
{
TextBoxMachineDescription.Text = "Not Provided";
}
if (TextBoxMachineLocation.Text.Length <= 0)
{
TextBoxMachineLocation.Text = "Not Provided";
}
if (TextBoxWorkRequired.Text.Length <= 0)
{
TextBoxWorkRequired.Text = "Not Provided";
}
if (TextBox9.Text == "Safety" && e.AffectedRows==1)
{
{
bool isLocal = HttpContext.Current.Request.IsLocal;
if (isLocal == true)
{
string id = TextBox13.Text.ToString();
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
mm.From = new System.Net.Mail.MailAddress("no_reply_workorder#.com");//who send
mm.To.Add(new System.Net.Mail.MailAddress("abc#.com"));
//abc#abc.com
mm.Subject = "WorkOrders Type Safety";
mm.Body = "DO NOT REPLY TO THIS EMAIL" + "<br><br/>" + "WorkOrderNumber"
+ ": " + "<a href=\"http://localhost:49695/SafetyReport.aspx?WorkOrderNum=" + TextBox13.Text + "\">"
+ TextBox13.Text + "</a>" + "<-Click on the Work Order Number For Report"
+ "<br><br/>" + "WorkOrderNumber" + ": " +
"<a href=\"http://localhost:49695/Safety.aspx?WorkOrderNum=" +
TextBox13.Text + "\">" + TextBox13.Text + "</a>" +
"<-Click on this Work Order Number To Enter Data" +
"<br><br/>" + "Requestor" + ": " + TextBoxRequestor.Text +
"<br><br/>" + "Date" + ": " + TextBoxDate.Text +
"<br><br/>" + "Department" + ": " + TextBox14.Text +
"<br><br/>" + "Machine Description" + ": " +
TextBoxMachineDescription.Text + "<br><br/>" +
"Machine Location" + ": " +
TextBoxMachineLocation.Text + "<br><br/>" +
"Work Required" + ": " + TextBoxWorkRequired.Text + "<br><br/>"
mm.IsBodyHtml = true;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = ConfigurationManager.AppSettings["smtpServer"];
client.Send(mm);
captureuseremail();
}
}
}
}
i see an DetailsView1_Item Inserting how can i check if that is inserting into the sql database?? if the inserting is successful i like to set a boolean value to true and if true then perform the Details_View1 Inserted and send email else cancel the insert.
i am also using the insert button that comes with the details view. please ask me for additional code if your confused and i would more than happily provide it.
please help :(
Added Additional code:
INSERT INTO Master(Requestor, Date, Department, CompletionDate, MachineDescription,
MachineLocation, [Type of Work Order], [Work Required], Status)
VALUES (#Requestor, #Date, #Department, #CompletionDate,
#MachineDescription, #MachineLocation, #Type_of_Work_Order,
#Work_Required, #Status); SET #NewId = Scope_Identity()
i just have a bool successfull; which i set to true at the end of Item_Inserting method().
when user clicks submit on the details view which is nothing but the command button insert then the code hits the item_inserting takes all the value
Item_Inserting of the details view:
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
if (Page.IsValid)
{
//TextBox TextBoxWorkOrderNumber = (TextBox)(DetailsView1.FindControl("TextBox11"));
TextBox TextBoxRequestor = (TextBox)(DetailsView1.FindControl("TextBox3"));
TextBox TextBoxDate = (TextBox)(DetailsView1.FindControl("TextBox1"));
//TextBoxDate.Text = DateTime.Now.ToShortDateString();
TextBox TextBoxDepartment = (TextBox)(DetailsView1.FindControl("TextBox4"));
TextBox TextBoxCompletionDate = (TextBox)(DetailsView1.FindControl("TextBox16"));
TextBox TextBoxMachineDescription = (TextBox)(DetailsView1.FindControl("TextBox5"));
TextBox TextBoxMachineLocation = (TextBox)(DetailsView1.FindControl("TextBox6"));
TextBox TextBoxWorkRequired = (TextBox)(DetailsView1.FindControl("TextBox7"));
// DropDownList status = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
TextBox TextBoxStatus = (TextBox)(DetailsView1.FindControl("TextBox12"));
TextBoxStatus.Text = "Open";
DropDownList list = (DropDownList)(DetailsView1.FindControl("DropDownList1"));
TextBox9.Text = list.SelectedValue;
DropDownList lists = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
TextBox14.Text = lists.SelectedValue;
if (TextBoxRequestor.Text.Length <= 0)
{
TextBoxRequestor.Text = "Not Applicable";
}
if (TextBox14.Text.Length <= 0)
{
TextBoxDepartment.Text = "Not Provided";
}
if (TextBoxCompletionDate.Text.Length <= 0)
{
TextBoxCompletionDate.Text = "Not Provided";
}
if (TextBoxMachineDescription.Text.Length <= 0)
{
TextBoxMachineDescription.Text = "Not Provided";
}
if (TextBoxMachineLocation.Text.Length <= 0)
{
TextBoxMachineLocation.Text = "Not Provided";
}
if (TextBoxWorkRequired.Text.Length <= 0)
{
TextBoxWorkRequired.Text = "Not Provided";
}
successfull = true;
}
else
{
e.Cancel = true;
successfull = false;
}
}
This is Where the actual insert takes place, its my sqldatasource:
**all the values from the item_inserting are inserted here with an identity value **
protected void RequestorSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
if (successfull == true)
{
try
{
int newid = (int)e.Command.Parameters["#NewId"].Value;
TextBox13.Text = newid.ToString();
}
catch
{
successfull = false;
}
if (e.AffectedRows == 1 && successfull == true)
{
successfull = true;
}
else
{
successfull = false;
}
}
else
{
successfull = false;
}
}
the issue is the email is still getting sent when i stop the program, how can i create a bad insert like i want it to fail similar what is happening to the user i am not able to recreate the issue for example i tried adding a new field in the insert statement but did not give it any values and the error it threw was you have more columns then values.
This is a picture of my details view:
**all of the .cs code at http://pastebin.com/6VC6FZK7 and the .aspx code at http://pastebin.com/QhjWNNt0 ** hope this helps out a bit.

If you just setting the bool successful to true after the insert and have not done any error checking then it can fail and still send the email. I suggest either wrapping the insert code in a TRY..CATCH..and set the succssful state to false in the catch OR running a IF...ELSE.. to check if the data was inserted correctly and setting the successful state there.

Related

Alternative for If-else

I'm a noob programmer, 1 month into my first class. Right now i'm fooling around making a WINFORM-application in C# that is supposed to some sort of cash register for a bar.
The form consists of:
- 6 buttons named Drank1 to Drank6
- one OK button
- One textbox and button named total.
- a reset-button that accompanies each "drank" button.
The essence of the form is: you type in name, type, content and price in the textboxes and one of the drankbuttons gets a name & value. after youve named these buttons, you can press them a desirable amount of times then press total to get the price of every drink combined.
The form works as expected but i whas wondering. I wrote a if-else statement connected to the pressing of the OK button that needs to be pressed in order to declare values to the buttons.
I did this with the following piece of code.
private void btnValidate_Click(object sender, EventArgs e)
{
if (btnDrank1.Text == "Drank1")
{
btnDrank1.Text = txtNaam.Text + "\n" + txtInhoud.Text + "cl";
drank[0].Naam = txtNaam.Text;
drank[0].Inhoud = txtInhoud.Text;
drank[0].Prijs = Convert.ToDouble(txtPrijs.Text);
}
else
{
if (btnDrank2.Text == "Drank2")
{
btnDrank2.Text = txtNaam.Text + "\n" + txtInhoud.Text + "cl";
drank[1].Naam = txtNaam.Text;
drank[1].Inhoud = txtInhoud.Text;
drank[1].Prijs = Convert.ToDouble(txtPrijs.Text);
}
else
{
if (btnDrank3.Text == "Drank3")
{
btnDrank3.Text = txtNaam.Text + "\n" + txtInhoud.Text + "cl";
drank[2].Naam = txtNaam.Text;
drank[2].Inhoud = txtInhoud.Text;
drank[2].Prijs = Convert.ToDouble(txtPrijs.Text);
}
else
{
if (btnDrank4.Text == "Drank4")
{
btnDrank4.Text = txtNaam.Text + "\n" + txtInhoud.Text + "cl";
drank[3].Naam = txtNaam.Text;
drank[3].Inhoud = txtInhoud.Text;
drank[3].Prijs = Convert.ToDouble(txtPrijs.Text);
}
else
{
if (btnDrank5.Text == "Drank5")
{
btnDrank5.Text = txtNaam.Text + "\n" + txtInhoud.Text + "cl";
drank[4].Naam = txtNaam.Text;
drank[4].Inhoud = txtInhoud.Text;
drank[4].Prijs = Convert.ToDouble(txtPrijs.Text);
}
else
{
if (btnDrank6.Text == "Drank6")
{
btnDrank6.Text = txtNaam.Text + "\n" + txtInhoud.Text + "cl";
drank[5].Naam = txtNaam.Text;
drank[5].Inhoud = txtInhoud.Text;
drank[5].Prijs = Convert.ToDouble(txtPrijs.Text);
}
else
{
MessageBox.Show("6 dranken is genoeg!", "My Application",
MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
}
I was wondering if there is a way to reduce the amount of code and still get the same result. I was thinking maybe a foreach loop, but can't quite figure out how exactly to write one with custom classes.
Cheers
What you want is called a switch statement.
http://www.dotnetperls.com/string-switch
It would end up looking something like this:
switch (btnDrank2.Text)
{
case "Drank2":
btnDrank2.Text = txtNaam.Text + "\n" + txtInhoud.Text + "cl";
drank[1].Naam = txtNaam.Text;
drank[1].Inhoud = txtInhoud.Text;
drank[1].Prijs = Convert.ToDouble(txtPrijs.Text);
break;
case "Drank3":
btnDrank3.Text = txtNaam.Text + "\n" + txtInhoud.Text + "cl";
drank[2].Naam = txtNaam.Text;
drank[2].Inhoud = txtInhoud.Text;
drank[2].Prijs = Convert.ToDouble(txtPrijs.Text);
break;
}
etc. The code may have errors as I do not have access to a c# compiler.
Use the switch statement. in you case the code would be something like that
private void btnValidate_Click(object sender, EventArgs e)
{
string text = btnDrank4.Text;
switch(text)
{
case "Drank1":
btnDrank1.Text = txtNaam.Text + "\n" + txtInhoud.Text + "cl";
drank[0].Naam = txtNaam.Text;
drank[0].Inhoud = txtInhoud.Text;
drank[0].Prijs = Convert.ToDouble(txtPrijs.Text);
break;
case "Drank2":
// your code here
break;
// here the other cases
default ""
// here everything is not the previous values
// I suppose these lines
MessageBox.Show("6 dranken is genoeg!", "My Application",
MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
break;
}
}

Show Brackets in Asp.net

when users login to their account then i show their names and also their designations it works but when i show designation it shows like mix means that username+designation for example JOHNMANAGER .here manager is desgination and same like this happend in my side but i want designations type in brackets.
here is code
string desginname = Convert.ToString(loginusers.spdesignname(txt_username.Value, txt_pass.Value));
Session["UserDesignationName"] = desginname;
if (users == 1)
{
Session["Login2"] = txt_username.Value;
Session["Login3"] = txt_pass.Value;
Session["UserDesignationID"] = desginid;
//Session["DepartmentID"] = depid; ;
Session["UserDesignationName"] = desginname;
Session["UserTypeID"] = users;
Response.Redirect("alldocuments.aspx");
}
else if (users == 2)
{
Session["Login2"] = txt_username.Value;
Session["Login3"] = txt_pass.Value;
Session["UserDesignationID"] = desginid;
Session["UserDesignationName"] = desginname;
Session["UserTypeID"] = users;
Response.Redirect("alldocuments.aspx");
}
}
catch
{
errrros.Text = "Incorrect User Name or Password";
}
and here is in site master ...
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["Login2"] != null & Session["UserDesignationName"]!=null)
{
["UserDesignationID"].ToString();
WELCOME.Text = Session["Login2"].ToString() +Session
[("UserDesignationName")].ToString();
}
lbtnLogout.Visible = Session["Login2"] != null || Session["Login2"] !=
null;
}
}
and here is the image
image
Add them in where you build the welcome text:
WELCOME.Text = Session["Login2"].ToString() + " (" + Session
[("UserDesignationName")].ToString() + ")";
or better, use String.Format:
WELCOME.Text = String.Format("{0} ({1})",
Session["Login2"].ToString(),
Session[("UserDesignationName")].ToString());
Try This.
WELCOME.Text = Session["Login2"].ToString() +
" (" + Session["UserDesignationName"].ToString() +")";
Just use following line of code if designation name is not supplied.
WELCOME.Text = Session["Login2"].ToString() + (Session["UserDesignationName"].ToString()!="" ? " (" + Session["UserDesignationName"].ToString() + ")" : string.Empty) ;

drop down comboBox if else statement error [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
If I write in cmbGrNo.text then there will be an
Input string is not in correct format
How can I identify that which combobox is edit?
I write in combobox and then click on search button the compiler is giving me error cause it does not accept the other combobox text. It only accepts the value of first one ...
please help me
HERE IS THE CODE
private void btnSearch_Click(object sender, EventArgs e)
{
if (cmbAdmissionNo.Text.Length == 0 && cmbRollNo.Text.Length == 0 && cmbStudentName.Text.Length == 0 && cmbGRNo.Text.Length == 0)
{
MessageBox.Show("Enter Student Name OR Admission No OR Gr No OR Roll No"," INSERT FIELDS", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (StudentDBClass.CheckStudent(cmbStudentName.Text))
{
DataTable dt = StudentDBClass.getTableBYStdName(cmbStudentName.Text);
txtAdminNo.Text = "Admission No : " + dt.Rows[0]["AddmissionNo"];
txtGrNo.Text = "GR No : " + dt.Rows[0]["GRNo"];
txtClass.Text = "Class : " + dt.Rows[0]["ClassName"];
txtStudentName.Text = "Student Name : " + dt.Rows[0]["StudentName"];
txtFatherName.Text = "Father Name : " + dt.Rows[0]["FatherName"];
txtRollNo.Text = "Roll No: " + dt.Rows[0]["RollNo"];
dgvStdFeeCollection.DataSource = null;
dgvStdFeeCollection.DataSource = StudentFeeCollectionDBClass.getStdNameForDgvFeeCollection(cmbStudentName.Text);
cmbAdmissionNo.SelectedIndex = -1;
cmbGRNo.SelectedIndex = -1;
cmbRollNo.SelectedIndex = -1;
cmbAdmissionNo.Text = string.Empty;
cmbGRNo.Text = string.Empty;
cmbRollNo.Text = string.Empty;
}
else if (StudentDBClass.CheckWithAdmissionNo(Convert.ToInt32(cmbAdmissionNo.Text)))
{
DataTable dt = StudentDBClass.getTableBYAddmissionNo(Convert.ToInt32(cmbAdmissionNo.Text));
txtAdminNo.Text = "Admission No : " + dt.Rows[0]["AddmissionNo"];
txtGrNo.Text = "GR No : " + dt.Rows[0]["GRNo"];
txtClass.Text = "Class : " + dt.Rows[0]["ClassName"];
txtStudentName.Text = "Student Name : " + dt.Rows[0]["StudentName"];
txtFatherName.Text = "Father Name : " + dt.Rows[0]["FatherName"];
txtRollNo.Text = "Roll No: " + dt.Rows[0]["RollNo"];
dgvStdFeeCollection.DataSource = null;
dgvStdFeeCollection.DataSource = StudentFeeCollectionDBClass.getAdmissionNoForDgvFeeCollection(Convert.ToInt32(cmbAdmissionNo.Text));
cmbStudentName.SelectedIndex = -1;
cmbGRNo.SelectedIndex = -1;
cmbRollNo.SelectedIndex = -1;
cmbGRNo.Text = string.Empty;
cmbStudentName.Text = string.Empty;
cmbRollNo.Text = string.Empty;
}
else if (StudentDBClass.CheckGRNo(Convert.ToInt32(cmbGRNo.Text)))
{
DataTable dt = StudentDBClass.getTableGrNo(Convert.ToInt32(cmbGRNo.Text));
txtAdminNo.Text = "Admission No : " + dt.Rows[0]["AddmissionNo"];
txtGrNo.Text = "GR No : " + dt.Rows[0]["GRNo"];
txtClass.Text = "Class : " + dt.Rows[0]["ClassName"];
txtStudentName.Text = "Student Name : " + dt.Rows[0]["StudentName"];
txtFatherName.Text = "Father Name : " + dt.Rows[0]["FatherName"];
txtRollNo.Text = "Roll No: " + dt.Rows[0]["RollNo"];
dgvStdFeeCollection.DataSource = null;
dgvStdFeeCollection.DataSource = StudentFeeCollectionDBClass.getGrNoForDgvFeeCollection(Convert.ToInt32(cmbGRNo.Text));
cmbAdmissionNo.SelectedIndex = -1;
cmbStudentName.SelectedIndex = -1;
cmbRollNo.SelectedIndex = -1;
cmbAdmissionNo.Text = string.Empty;
cmbStudentName.Text = string.Empty;
cmbRollNo.Text = string.Empty;
}
This error occurs when the Convert.ToInt32 receives a string that its not able to parse.
You are selecting the text value of the combobox, this will not return an integer.
You need to select the SelectedValue of the combobox.
Something like this:
Convert.ToInt32(cmbGrNo.SelectedValue.Text)

response redirect makes session_end in global asax

I am getting frustrated due to the session become null.When I click on save button I save the data to DB from code behind and if this successfully I am redirecting the user to the main projects page,using syntax:
Response.Redirect("~/Admin/Projects.aspx?i=esc&prjName=abc",'false');
but its make my session null.Its goes to Globex.asax page ang executes the Session_End and make all session null.
I even tried Server.Transfer but by this the browser url remains same and client doesn't want this.Even some where I read that the Server.Execute is also used to redirect but it is showing some wrong results.
can I use the Response.Redirect without this session null problem ??
(In this page I am creating the text file to store some long description and if this is successful then I am redirecting to the another page.)
Update::
here is my code for button click
protected void lnkbtnAddDescription_Click(object sender, EventArgs e)
{
try
{
if ((!hidProjId.Value.ToString().Equals("") || !hidEditProjId.Value.ToString().Equals("")) && !txtDescription.Value.ToString().Equals(""))
{
//ProjectDescription
int projId = 0;
if (!hidIsEdit.Value.ToString().Equals(""))
{
projId = Convert.ToInt32(hidEditProjId.Value.ToString());
}
else
{
projId = Convert.ToInt32(hidProjId.Value.ToString());
}
ProjectM proj = new ProjectM();
proj.LoadByKey(projId);
string prj = proj.ProjectName.ToString().Replace(" ", "-");
string strDirectoryPath = Server.MapPath("~/ProjectDescription/") + proj.ProjectId + "-" + prj;
if (!Directory.Exists(strDirectoryPath))
{
Directory.CreateDirectory(strDirectoryPath);
string filePath = strDirectoryPath + "/" + proj.ProjectId + "-" + prj + ".txt";
string strDescription = txtDescription.Value.ToString().Replace("<br />", "<p>");
createTextFile(filePath, strDescription);
string dbDirectoryPath = "~/ProjectDescription/" + proj.ProjectId + "-" + prj + "/" + proj.ProjectId + "-" + prj + ".txt";
proj.Description = dbDirectoryPath.ToString();
proj.IsNew = false;
proj.Save();
if (!hidIsEdit.Value.ToString().Equals(""))
{
//Server.Execute("~/SuperAdmin/Projects.aspx?i=esc&prjName=" + proj.ProjectName.ToString() + "",false);
Session["dsProj"] = null;
Session["editProjId"] = null;
Session["fname"] = hidFname.Value.ToString();
Session["UserId"] = hidUserId.Value.ToString();
Session["role"] = hidRole.Value.ToString();
Response.Redirect("~/SuperAdmin/Projects.aspx?i=esc&prjName=" + proj.ProjectName.ToString());
}
else
{
//Server.Execute("~/SuperAdmin/Projects.aspx?i=sc&prjName=" + proj.ProjectName.ToString() + "",false);
Session["dsProj"] = null;
Session["editProjId"] = null;
Session["fname"] = hidFname.Value.ToString();
Session["UserId"] = hidUserId.Value.ToString();
Session["role"] = hidRole.Value.ToString();
Response.Redirect("~/SuperAdmin/Projects.aspx?i=sc&prjName=" + proj.ProjectName.ToString());
}
}
else
{
Directory.Delete(strDirectoryPath, true);
Directory.CreateDirectory(strDirectoryPath);
string fileName = proj.ProjectName.ToString().Replace(" ", "-");
string filePath = strDirectoryPath + "/" + proj.ProjectId + "-" + fileName + ".txt";
string strDescription = txtDescription.Value.ToString().Replace("<br>", "<p>");
createTextFile(filePath, strDescription);
string dbDirectoryPath = "~/ProjectDescription/" + proj.ProjectId + "-" + proj.ProjectName.ToString() + "/" + proj.ProjectId + "-" + proj.ProjectName.ToString() + ".txt";
proj.Description = dbDirectoryPath.ToString();
proj.IsNew = false;
proj.Save();
if (!hidIsEdit.Value.ToString().Equals(""))
{
//Server.Execute("~/SuperAdmin/Projects.aspx?i=esc&prjName=" + proj.ProjectName.ToString() + "", false);
Session["dsProj"] = null;
Session["editProjId"] = null;
Session["fname"] = hidFname.Value.ToString();
Session["UserId"] = hidUserId.Value.ToString();
Session["role"] = hidRole.Value.ToString();
Response.Redirect("~/SuperAdmin/Projects.aspx?i=esc&prjName=" + proj.ProjectName.ToString());
}
else
{
//Server.Execute("~/SuperAdmin/Projects.aspx?i=sc&prjName=" + proj.ProjectName.ToString() + "", false);
Session["dsProj"] = null;
Session["editProjId"] = null;
Session["fname"] = hidFname.Value.ToString();
Session["UserId"] = hidUserId.Value.ToString();
Session["role"] = hidRole.Value.ToString();
Response.Redirect("~/SuperAdmin/Projects.aspx?i=sc&prjName=" + proj.ProjectName.ToString());
}
}
}
}
catch (Exception)
{
}
}
private void createTextFile(string filePath, string strDescription)
{
try
{
StreamWriter w = File.CreateText(filePath);
w.WriteLine(strDescription);
w.Flush();
w.Close();
}
catch (Exception ex)
{
}
}
Before you redirect to the next page,
assign the existing session value in the button click event also.
This would solve the problem.
hope this will be helpful to you,
ASP.NET Session becomes null after postback on local
This think your problem is related to some kind of permission denial, which is nulling your session.
There must be a problem in creating or saving the text file.
This may be making Session_End call so you are getting all values null.
Folder delete, move, rename causes Session end and long refresh
http://www.telerik.com/community/forums/aspnet-ajax/file-explorer/folder-delete-move-rename-causes-session-end-and-long-refresh.aspx#1365780

C# Adding values to pictureboxes

I just recently posted something earlier regarding a C# game project I am working on in Microsoft visual C# express and after trial and error the code that I have presented underneath will not work. Does anyone have any advice or help they could give me on how to get it to work? the part of the code with the brackets and asterisks and arrows is the error that will not work for me. (NOTE: I am making a Form on Microsoft Visual C# express.)
if (buttonFlag[0])
{
return;
}
if (accept)
{
return;
}
textBox2.Text = "";
textBox1.Text = "";
offerCounter++;
---> [[[ **pictureBox2.Image**]]]<--- = tempLabel = buttonList[0].ToString();
LostValues(tempLabel);
textBox1.Text = "-> you just opend " + tempLabel + "\n";
CallZero(tempLabel);
if (offerCounter == 20)
{
finalValue = GetFinalValue();
MessageBox.Show("You win " + finalValue.ToString());
textBox1.Text = "Game is over" + "\n";
textBox1.Text += "you won: " + finalValue.ToString();
label16.Content = "you won:";
label17.Content = finalValue.ToString();
label18.Text = "Game Over";
accept = true;
}
if (offerCounter <= 18)
{
if ((offerCounter % 3) == 0)
{
GenerateNewOffer();
textBox1.Text += "-> you have a new offer ";
MessageBox.Show("you recieved a new offer !");
textBox2.Text = newOffer.ToString();
}
else
{
offerRemainder = 3 - (offerCounter % 3);
textBox1.Text += "-> Open " + offerRemainder.ToString() + "more box(es) for new offer";
}
}
else
{
textBox2.Text = "";
}
The PictureBox.Image Property takes an Image instance. Read MSDN for both and code accordingly.

Categories