kannan
kannan

Reputation: 421

How can i give message alert box in asp.net

how can i give message box alert in asp.net Webpage By checking the username and password by membership in 'if' statement and in 'else' i should display the alert box as"enter valid username and password"(i checked the 'if' but i don't know how to give alert message in 'else')

if (Membership.ValidateUser(txtUserName.Text, txtPassword.Text))
           {

           }
           else
           {
               // Here i have to display message box alert
           }

Please help me to solve this issue as soon as possible.

Upvotes: 0

Views: 18922

Answers (4)

Amit Singh
Amit Singh

Reputation: 8109

Try like this...Add following code in your else part...

ClientScript.RegisterClientScriptBlock(this.GetType(),"alert","Your Message",true);

Upvotes: 2

Shailesh
Shailesh

Reputation: 990

use this function for generic

public void MessageBox(string msg)
        {
            Page page = HttpContext.Current.Handler as Page;
            ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + msg + "');", true);
        }

Upvotes: 1

Neeraj
Neeraj

Reputation: 4489

Hey Alert popup is registered to based on condition.

If you want to registered on Page load use this.

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", "alert('your message')", true);

If want to be registered any specific block use this.

ClientScript.RegisterClientScriptBlock(this.GetType(),"alert","Your Message",true);

Upvotes: 0

Amit
Amit

Reputation: 15387

Try this

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", "alert('your message')", true); 

Upvotes: 1

Related Questions