Hi
This is similar to my previous post but as there are issues with Goddady mail server and sending message through code behind i decide to find another way to make my job work in others way.
In "ads" table where those info into controllers below will be stored, the table has "AdsID" column which generate automatic number of each row. So what i am looking for is after inserting the info form controllers inside table , get the AdsID number of row which just created when the button clicked and pass the row number "AdsID" and "AdsTit" through EditAds.aspx. so the link suppose to be such as:
EditAds.aspx?AdTit= here AdsTit &AdNum= here AdsID
protected void adNewQdadsbtn_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(sc);
if (RegInteFileUploadImg1.HasFile || RegInteFileUploadImg2.HasFile || RegInteFileUploadImg3.HasFile || RegInteFileUploadImg4.HasFile || RegInteFileUploadImg5.HasFile)
{
var files = new[] { FileExtentio, FileExtentio2, FileExtentio3, FileExtentio4, FileExtentio5 };
files = files.Where(s => !string.IsNullOrEmpty(s)).ToArray();
var extensions = new[] { ".jpg", ".png" };
if ((files.Except(extensions).Count()) <= 0)
{
if (RegDropDownList3.SelectedValue == "no")
{
AdsWrngPanel.Visible = true;
adsstutslbel.Text = "- Please select ads status";
}
else
{
}
if (DropDownList11.SelectedValue == "no")
{
AdsWrngPanel.Visible = true;
adscondlbel.Text = "- Please select ads condition";
}
string sqlstatment = @"INSERT INTO ads (Section, Category, AdsTit, AdsDesc, Country, State,AdsDate,
City, AdsPrice, Img1, img2, img3, img4,img5, Wtags, QAdsTeleNum,Condition, Status,Maker,Year,Gear,RoomNo,
Space,Shower,Garage,Currency,extlink,AdType,approvAds,QAdsEmail)
VALUES (@Section, @Category, @AdsTit, @AdsDesc, @Country, @State,@adsDate, @City, @AdsPrice, @Img1, @img2, @img3,
@img4, @img5, @Wtags, @QAdsTeleNum,@Condition, @Status,@Maker,@Year,@Gear,@RoomNo,@Space,@Shower,@Garage,@Currency, @extlink,@AdType,@approvAds,@QAdsEmail)";
SqlCommand cmd = new SqlCommand(sqlstatment, cn);
String shw = "Y";
cmd.Parameters.AddWithValue("@Section", RegSecdrdoads.SelectedItem.Text);
cmd.Parameters.AddWithValue("@AdsTit", addadstittxtbx.Text);
cmd.Parameters.AddWithValue("@AdsDesc", NyAdsDesc);
cmd.Parameters.AddWithValue("@Country", cookie.Value);
....
string imgnouser = "/images/general/nouser.jpg";
if (RegInteFileUploadImg1.HasFile)
{
cmd.Parameters.AddWithValue("@Img1", RegInteFileUploadImg1.FileName);
RegInteFileUploadImg1.SaveAs(Server.MapPath("~/images/AdsImgs/" + RegInteFileUploadImg1.FileName));
}
else
{
cmd.Parameters.AddWithValue("@Img1", imgnouser);
}
if (RegInteFileUploadImg2.HasFile)
{
cmd.Parameters.AddWithValue("@Img2", RegInteFileUploadImg2.FileName);
RegInteFileUploadImg2.SaveAs(Server.MapPath("~/images/AdsImgs/" + RegInteFileUploadImg2.FileName));
}
else
{
cmd.Parameters.AddWithValue("@Img2", imgnouser);
}
cn.Open();
cmd.ExecuteNonQuery();
Response.Redirect("User panel.aspx");
}
else
{
AddNwAddsWrngFrmtLbl.Text = "Error: The file should have .png or .jpg format only";
AddNwAddsWrngFrmtLbl.ForeColor = System.Drawing.Color.Red;
return;
}
}
else
{
string sqlstatment2 = @"INSERT INTO ads (Section, Category, AdsTit, AdsDesc, Country, State,AdsDate,
City, AdsPrice, Wtags, QAdsTeleNum,Condition, Status,Maker,Year,Gear,RoomNo, Space,Shower,Garage,extlink,AdType,approvAds,QAdsEmail)
VALUES (@Section, @Category, @AdsTit, @AdsDesc, @Country, @State,@adsDate, @City, @AdsPrice, @Wtags, @QAdsTeleNum,@Condition,
@Status,@Maker,@Year,@Gear,@RoomNo,@Space,@Shower,@Garage, @extlink,@AdType,@approvAds,@QAdsEmail)";
SqlCommand cmd = new SqlCommand(sqlstatment2, cn);
String SHO = "Y";
cmd.Parameters.AddWithValue("@Section", RegSecdrdoads.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Maker", makervalue);
cmd.Parameters.AddWithValue("@Year", Yearvalue);
cmd.Parameters.AddWithValue("@Gear", Gearvalue);
cmd.Parameters.AddWithValue("@RoomNo", RoomNum);
cmd.Parameters.AddWithValue("@Space", areasize);
cmd.Parameters.AddWithValue("@Category", RegCatedrdoads.SelectedItem.Text);
cmd.Parameters.AddWithValue("@AdsTit", addadstittxtbx.Text);
cmd.Parameters.AddWithValue("@AdsDesc", NyAdsDesc);
cmd.Parameters.AddWithValue("@extlink", extlinktxtbox.Text);
cmd.Parameters.AddWithValue("@QAdsEmail", QuickAdsEmailTxtBox.Text);
cn.Open();
cmd.ExecuteNonQuery();
}
string QAdsID = string.Empty;
string QADSTit = string.Empty;
using (SqlCommand SendMailcmd = new SqlCommand("SELECT AdsID FROM ads WHERE QAdsEmail = @QAdsEmail AND AdsTit=@AdsTit OR QAdsTeleNum=@QAdsTeleNum"))
{
SendMailcmd.Parameters.AddWithValue("@AdsTit", addadstittxtbx.Text.Trim());
SendMailcmd.Parameters.AddWithValue("@QAdsEmail", QuickAdsEmailTxtBox.Text.Trim());
SendMailcmd.Parameters.AddWithValue("@QAdsTeleNum", QuickAdsMobNumTxtBox.Text.Trim());
SendMailcmd.Connection = cn;
using (SqlDataReader sdr = SendMailcmd.ExecuteReader())
{
if (sdr.Read())
{
QAdsID = sdr["AdsID"].ToString();
QADSTit = sdr["AdsTit"].ToString();
}
}
cn.Close();
}
Response.Redirect("EditAds.aspx?QADSID=QAdsID&QADSTit=QADSTit");
}