if(blah) alert box else somethinge useful

G

Guest

hey guys this may not be possible, but i have an if statement that checks to
see if a value returned by a sql query is null or not..if it is i execute the
right code if it has a value i need to tell the user about the problem. i was
thinking just an alert box, but i dont know how to do that from the
codebehind aside from asigning it to the buttons onclick event, but the
button already has a confirm box in its onclick.

try {
myConnection = new SqlConnection(connectionString);
myConnection.Open();
cmdIsMaster = new SqlCommand("Select MasterPIN From PIN Where PIN="+PIN,
myConnection);
myReader = cmdIsMaster.ExecuteReader();
myReader.Read();
if(myReader.GetInt32(0).ToString() != null)
{
myReader.Close();
alert("This PIN has a Master that is not active please reactivate
MasterPIN"+myReader.GetInt32(0).ToString());
Response.Redirect("Default.aspx");
}
else

now for some reason the person who had this job before me, put the events in
a switchboard.aspx file and in its codebehind instead of using the codebehind
of default.aspx. i tried putting some of htis code in the default.aspx.cs
file but it wouldnt fire. it works fine in the switchboard.aspx.cs file when
you could delete or reactivate anything, but my boss wanted me to make sure
they didnt reactivate a subpin w/out the master bieng activated, beacuse the
sub wont work w/out the master.
 
M

Mike Salter

John:

I use some code I found, listed below. There may be a better way, but it
works.

private void ASPNET_MsgBox(string strMessage)
{
System.Web.HttpContext.Current.Response.Write("<SCRIPT
LANGUAGE='JavaScript'>" + Convert.ToChar(13) + Convert.ToChar(10));
System.Web.HttpContext.Current.Response.Write("alert('" + strMessage +
"');" + Convert.ToChar(13) + Convert.ToChar(10));
System.Web.HttpContext.Current.Response.Write("</SCRIPT>");
}
 
P

Peter Rilling

You would need to use a method like RegisterStartupScript to output the
necessary JavaScript for displaying the alert.
 
G

Guest

do i need to use both or just one?, and would it be possible to email me the
code @ (e-mail address removed) so i dont make a mistake changing out the html crap for
real characters. thanks for the quick responses guys
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top