|
I have the following class code to add support ticket:
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;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Globalization;
using Microsoft.Win32;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Security.Cryptography;
using DevExpress.Web.ASPxUploadControl;
using System.Drawing;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace volow
{
public class create_support_ticket
{
MySqlConnection support_sql_connection = null;
MySqlCommand support_sql_command = null;
public void add_support_ticket(string support_incident_title, string email_address, string support_ticket_description)
{
support_sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
support_sql_connection.Open();
support_sql_command = new MySqlCommand("sp_add_support_ticket", support_sql_connection);
support_sql_command.CommandType = CommandType.StoredProcedure;
support_sql_command.Parameters.Add("param_support_incident_title", MySqlDbType.VarChar).Value = support_incident_title;
support_sql_command.Parameters.Add("param_email_address", MySqlDbType.VarChar).Value = email_address;
support_sql_command.Parameters.Add("param_support_ticket_description", MySqlDbType.Text).Value = support_ticket_description;
int result_rows = support_sql_command.ExecuteNonQuery();
support_sql_command.Dispose();
support_sql_connection.Close();
HttpContext.Current.Session["message_title"] = "Thank you";
HttpContext.Current.Session["message_title_Color"] = Color.Blue.ToArgb();
HttpContext.Current.Session["message_text"] = "We have recieved your feedback and we will get back to you as soon as possible.";
HttpContext.Current.Session["message_button_title"] = "Back";
HttpContext.Current.Session["message_button_url"] = "Home.aspx";
if (!HttpContext.Current.Request.Path.EndsWith("Message.aspx", StringComparison.InvariantCultureIgnoreCase))
HttpContext.Current.Response.Redirect("Message.aspx");
}
}
}
and I am calling it from the webform like this:
protected void btnSend_Click(object sender, EventArgs e)
{
if (txtMessage.Text == "")
{
Session["message_title"] = "Error";
Session["message_title_Color"] = Color.Red.ToArgb();
Session["message_text"] = "Please enter your message.";
Session["message_button_title"] = "Back";
Session["message_button_url"] = Request.UrlReferrer.ToString();
}
create_support_ticket create_support_ticket = new create_support_ticket();
create_support_ticket.add_support_ticket(txtSubject.Text, txtEmailAddress.Text, txtMessage.XHTML);
}
but I am getting two rows added for every insert! Thsi first row is correct as per the passed information but the second row adding the Session["message_title"] as support_incdent_title and the Session["message_text"] as support_ticket_description and I really don't know how??
here is my stored procedure:
INSERT INTO support_incidents (support_incident_title, email_address) VALUES (param_support_incident_title, param_email_address);
INSERT INTO support_tickets (support_incident_id, support_ticket_description) VALUES (LAST_INSERT_ID(), param_support_ticket_description);
|
|
|
|
|
You have to wrap the contents of the button function in
If Not Page.IsPostback
'Your function stuff
End If
You'll nave to figure out the c sharp equivalent.
When you click the button, you fire a postback event, so the button code runs twice, runs on postback and runs on the page reloading.
|
|
|
|