Click here to Skip to main content
15,920,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
try
            {

                dbquery.getconnection(txtsname.Text, txtuname.Text, txtpwd.Text);
                pnlDB.Visible = true;
                pnlCN.Visible = true;
                ddlDB();
            }
            catch (Exception ex)
            {
                lblex.Visible = true;
                string p = ex.Message.ToString();

                lblex.Text = p;


                pnlDB.Visible = false;
                pnlCN.Visible = true;
            }



How can I show the catch error in an alert box on the server side?
Posted
Updated 7-Jul-11 22:57pm
v2
Comments
Reiss 8-Jul-11 5:00am    
Can you add a bit more detail about what you are trying to actually achieve, as surely no-one is logged in to the server to recieve such a message
suryaswathi 8-Jul-11 5:03am    
protected void btnConnect_Click(object sender, EventArgs e)
{
try
{

dbquery.getconnection(txtsname.Text, txtuname.Text, txtpwd.Text);
pnlDB.Visible = true;
pnlCN.Visible = true;
ddlDB();
}
catch (Exception ex)
{
lblex.Visible = true;
string p = ex.Message.ToString();
Response.Write("<script language='javascript'>alert(" + p + ")</script>");

lblex.Text = p;


pnlDB.Visible = false;
pnlCN.Visible = true;
}


}

i tried to connect server ..its not correct info it want to show error msg in alert box
serverside

 
Share this answer
 
Comments
Prerak Patel 8-Jul-11 5:07am    
:doh: I thought OP wants to see the error message on server itself, so I suggested logging.
I would suggest you to log the errors instead of showing message box at serverside.
Check the google[^] links to know more.
 
Share this answer
 
v2
I think you forgot the single quotes around the message string in alert method,

Response.Write("<script language='javascript'>alert('" + p + "')</script>");
 
Share this answer
 
You just add the following code

ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Your message');", true);


Please do not use Response.Write as it will mess up your css.
 
Share this answer
 
v3

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