TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bhavesh Vankar
763
1.1k
86.9k
Confirm message while record save in web c#
Dec 31 2020 10:27 AM
below is my code for record save in database but when i save record in being save without confirm message. i want to show first validation if any control is empty and when all the fields are filled and press save button confirm message should be fire and ask to save record. kidnly help me to solve this. where is error.
record directly being save without confrm message. i want to fire confirm message using code behind i have used validation control to validate all the fileds. i dont want to use javascrit confirm function. kindly suggest me c# code begind for the web application.
if
(IsPostBack)
{
if
(Page.IsValid)
{
string
image = simagehidden.Value;
if
(
string
.IsNullOrEmpty(image))
{
lblimgerror.Visible =
true
;
lblimgerror.Text =
"*"
;
lblimgerror.ForeColor = System.Drawing.Color.Red;
}
else
{
var WebClient =
new
WebClient();
byte
[] imgbytes = WebClient.DownloadData(image);
MemoryStream ms =
new
MemoryStream();
byte
[] imgtobinary =
new
byte
[ms.Length];
ms.Position = 0;
ms.Read(imgtobinary, 0, (
int
)ms.Length);
string
_imgpath = Path.Combine(Server.MapPath(
"~/CroppedImage/"
+ DateTime.Now.ToString(
"dd-MM-yy"
)));
sImage.ImageUrl = _imgpath;
SqlConnection con =
new
SqlConnection(
this
.con);
SqlCommand cmd =
new
SqlCommand(
"studentrec_test"
, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@S_ID"
, TxtAutovID.Text);
cmd.Parameters.AddWithValue(
"@S_NAMEOFVISITOR"
, txtfname.Text +
" "
+ txtmname.Text +
" "
+ txtlname.Text);
cmd.Parameters.AddWithValue(
"@S_ADDRESS"
, txtaddress.Text);
cmd.Parameters.AddWithValue(
"@S_CITY"
, txtcity.Text);
cmd.Parameters.AddWithValue(
"@S_TALUKA"
, txttaluka.Text);
cmd.Parameters.AddWithValue(
"@S_DIST"
, txtdistric.Text);
cmd.Parameters.AddWithValue(
"@S_PINCODE"
, txtpincode.Text);
cmd.Parameters.AddWithValue(
"@S_GENDER"
, DDgender.SelectedItem.ToString());
cmd.Parameters.AddWithValue(
"@S_BIRTHDATE"
, txtbod.Text);
cmd.Parameters.AddWithValue(
"@S_IDTYPE"
, dropidtype.SelectedItem.ToString());
cmd.Parameters.AddWithValue(
"@S_IDREF"
, txtidno.Text);
cmd.Parameters.AddWithValue(
"@S_PHONE"
, txtphoneno.Text);
cmd.Parameters.AddWithValue(
"@S_AGE"
, txtage.Text);
cmd.Parameters.AddWithValue(
"@S_EMPDEPARTMENT"
, dropdepartment.SelectedItem.ToString());
cmd.Parameters.AddWithValue(
"@S_PURPOSE"
, txtpurpose.Text);
cmd.Parameters.AddWithValue(
"@S_TOMEET"
, txtmeet.Text);
cmd.Parameters.AddWithValue(
"@S_EMPDESIGNATION"
, dropdesignation.SelectedItem.ToString());
cmd.Parameters.AddWithValue(
"@S_BLOCKNO"
, txtblock.Text);
cmd.Parameters.AddWithValue(
"@S_FLOORNO"
, txtfloor.Text);
cmd.Parameters.AddWithValue(
"@S_VEHICLE"
, checkvehicale.Checked);
cmd.Parameters.AddWithValue(
"@S_VEHICLENO"
, txtvehicleno.Text);
cmd.Parameters.AddWithValue(
"@S_VEHICLETYPE"
, dropvehicletype.SelectedItem.ToString());
cmd.Parameters.AddWithValue(
"@S_IMAGE"
, imgtobinary);
string
MainDir = @
"~/StudentImage/"
;
String SubDir = DateTime.Now.ToString(
"dd-MM-yyyy"
);
if
(!Directory.Exists(Server.MapPath(MainDir + SubDir +
"/"
)))
{
Directory.CreateDirectory(Server.MapPath(MainDir + SubDir +
"/"
));
}
string
imgname = (TxtAutovID.Text +
".jpg"
);
File.WriteAllBytes(Path.Combine(Server.MapPath(MainDir + SubDir), imgname), imgbytes);
cmd.Parameters.AddWithValue(
"@V_REMARKS"
, txtremark.Text);
cmd.Parameters.AddWithValue(
"@v_username"
,
"user"
/* Session["User"].ToString()*/
);
cmd.Parameters.AddWithValue(
"@v_photoflag"
,
true
);
cmd.Parameters.AddWithValue(
"@v_gateno"
,
"5"
);
ClientScriptManager CSM = Page.ClientScript;
if
(ReturnValue())
{
string
strconfirm =
"<script>if(window.confirm('Do You Want To Save Record.?'))</script>"
;
CSM.RegisterClientScriptBlock(
this
.GetType(),
"Confirm"
, strconfirm,
true
);
}
con.Open();
cmd.ExecuteNonQuery();
generateautonumber();
FillListBox();
sImage.ImageUrl =
null
;
ClearControls();
con.Close();
}
}
}
Reply
Answers (
7
)
search get data from two tables record
Image is gone when selecting checkbox in C# Web Application.