Click here to Skip to main content
15,886,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my system is actually should show the alert message without any input from users when the users come into the page or when they refresh it. it will identify the sqlcommand and work based on it.
actually i try to create my own but not working. any suggestion guys?

here is my code:
my c# code:
C#
if (Page.IsPostBack)
{
   SqlConnection connection = new SqlConnection("Data Source=MELINA_YEO-VAIO; Initial Catalog=InventorySystem; Integrated Security=True");
   connection.Open();
   SqlCommand abc = new SqlCommand("Select case when (P_Amount <= SafetyStockamount) then 'Limit stock has been reached' end as Alert from Product");
   Page.RegisterStartupScript("ScriptDescription", "<script type=\"text/javascript\"> alert('Limit stock has been reached');</script>");
}


my javascript code:
C#
<script type="text/javascript">
    alert('Limit stock has been reached!');
</script>
Posted
Updated 13-May-14 0:30am
v3
Comments
syed shanu 13-May-14 5:26am    
Chk this link :
http://stackoverflow.com/questions/22404248/how-to-show-alert-from-code-behind-after-page-loads-completely
hahaahahaahahhahahahhahaha 13-May-14 5:34am    
thank you for ur answer but this one only show how to create alert message. it does not need to connect to database. But mine should identify the data in database first before the alert message showing up. That's why i also input sqlcommand in my code above. Could you suggest me other solution ? :)
Thanks7872 13-May-14 5:58am    
So your issue is not with JavaScript alert. You aimed to check some condition and if that condition is true than you are suppose to show the alert,right?
hahaahahaahahhahahahhahaha 13-May-14 6:07am    
yaaa.. do you know how to do this??

First get value out of your DB. If you don't know how to do it see this : How to retrieve output parameter from Store procedure and get value in vb.net?[^] and Stored procedure output parameter asp.net c#[^]

Check this value against your condition and show the alert accordingly.

Regards..
 
Share this answer
 
v2
Comments
hahaahahaahahhahahahhahaha 13-May-14 7:43am    
@rohan both of ur example is referring to any textbox in the page that need to be filled by users meanwhile mine dont have any user input and directly identify the value from database. could you give me other guidance about it? thank you
Thanks7872 13-May-14 7:55am    
You misunderstood the solution. Dont follow threads as such. Your target is to get the value from DB. Whats the query for that depends on you. I dont understand what do you mean by "directly identify the value from database"? In order to know that value, you have to query your DB. Its obvious whats the problem?
hahaahahaahahhahahahhahaha 14-May-14 8:09am    
actually im doing inventory system where one of its function is to automatically detect the stock/product that has reach its limit by using alert message.<br>
for this case, i have product table that consist pid, pname, vendorid, productamount, lead time and safetystockamount.<br>
im doing it using c#.net (visual studio 2010). im using sql server for database.<br>
 <br>
in my page, i actually will show the product details by using gridview tool in visual studio by referring to product table in my database and when the user first come into the page, the alert message will come out. This alert message only will pop out if there is one or more product that reached its stock limit. If all the product amount are in more than safetyamount then this alert message will not coming up.<br>
 <br>
i tried it already , this is my code:

Page page = HttpContext.Current.Handler as Page;
if
(page != null)
{
string message = "Limit stock has been reached!";
ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + message + "');", true);
}
}



class SqlCommandDemo
{
SqlConnection conn;

public SqlCommandDemo()
{
// Instantiate the connection
conn = new SqlConnection("Data Source=MELINA_YEO-VAIO; Initial Catalog=InventorySystem; Integrated Security=True");
}



protected void ReadData(object sender, EventArgs e)
{
SqlDataReader rdr = null;

try
{

conn.Open();


SqlCommand cmd = new SqlCommand("Select case when (P_Amount <= SafetyStockamount) then 'Limit stock has been reached' end as Alert from Product", conn);


rdr = cmd.ExecuteReader();


while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
finally
{

if (rdr != null)
{
rdr.Close();
}

if (conn != null)
{
conn.Close();
}
}
}
}
}

but this code also not working. when i execute the code, the desired page does not show up @@
which part of it that i do wrong?
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "Javascript:alert('msg');", true);
 
Share this answer
 
Comments
hahaahahaahahhahahahhahaha 13-May-14 5:44am    
@anup kumar ya yours also works to show only the alert message without condition. but mine should identify the data in database first before the alert message showing up. That's why i also input sqlcommand in my code above. Do you know where and how i can show up the alert message by identifying the sql command first? so for example if product amount already reached its limit then this alert message will show up. but the product amount has not reach it limit then this alert message will not popping up.
Can you try this

may be if i am not wrong

C#
string jScript;
jScript = "<script>alert('Limit stock has been reached.')</script>";
this.Page.RegisterStartupScript("keyClientBlock", jScript);
 
Share this answer
 
Comments
hahaahahaahahhahahahhahaha 13-May-14 5:40am    
@murugesan22 ya it works to show only the alert message without condition. but mine should identify the data in database first before the alert message showing up. That's why i also input sqlcommand in my code above. could u help me where i can put the sqlcommand to make it works?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900