2014年7月13日 星期日

[RESOLVED] show message to the user


hi


i have a changepass form


i want when the user entered the old password,check the data base and if the old password is wrong,show a message to the user,how can i show this message after the submit button is pressed?



You can show an alert() message. Our you can use a label at the top of the page to show your message. 



string sqlquery="select Password from TableName where Password='"+oldpass.text+"'";

// now use sqldata reader for reading the data.

if(!reader.Read())
{
// show messagebox by importing systems.windows.forms; pass doesnt match
}
else
{
//procced
}





creative-sh


how can i show this message after the submit button is pressed?


You can use the below code to show and alert message from code behind


protected void BtnSumbit_Click(object sender, EventArgs e)
{
//Your logic to see if user enterd an old password

//IF user enter then show the messsage
ScriptManager.RegisterClientScriptBlock(this, GetType(),"alertMessage", @"alert('You need to Provide a new Password, You cannot provide an already used password')", true);
}

Another Option is to Jquery Dialog controls. It has much more customizable options than alert message.


You can check the below link to show a Jquery Dialog from server side


http://www.aspsnippets.com/Articles/Open-Show-jQuery-UI-Dialog-Popup-Window-from-Server-Side-Code-Behind-in-ASPNet.aspx



Assuming you are in the same page, you could simply store the message in an existing Label Control if the password was incorrect :


// Check if your password was incorrect here
if(!isPasswordCorrect)
{
// Display an error message in an empty Label
YourErrorMessage.Text = "The password that was entered was incorrect.";
}

or if you wanted to actually display a Javascript alert notification, you could wire up the following simple script that would launch after the PostBack occurred using the
RegisterStartupScript method :


// Check if your password was incorrect here
if(!isPasswordCorrect)
{
// Display an error message in an empty Label
ClientScript.RegisterStartupScript(GetType(),"YourAlertScript","alert('The password entered was incorrect!');",true);
}

沒有留言:

張貼留言