简体   繁体   中英

Pop UP alert message from c# page

I need to show a pop up alert when some fileds have got not null values. I Used code piece like below , but not working correctly..Could you pls let me know the corrcet syntax for doing that?

    if (txtSearchName.Text != "" || cmbSearchOaO.SelectedItem.Text != "" || cmbVessel.SelectedItem.Text != "" || cmbSearchApplicationType.SelectedItem.Text != "" || cmbSearchHull.SelectedItem.Text != "" || cmbSearchCategory.SelectedItem.Text != "" || cmbSearchHazardCategory.SelectedItem.Text != "")
    {
        ScriptManager.RegisterClientScriptBlock(btApplySearch, btApplySearch, "<script> alert('Inserted successfully');</script>", true);
    }

Here btApplySearch is the buttonID used in aspx markup.

Try this:

if (txtSearchName.Text != "" || cmbSearchOaO.SelectedItem.Text != "" || cmbVessel.SelectedItem.Text != "" || cmbSearchApplicationType.SelectedItem.Text != "" || cmbSearchHull.SelectedItem.Text != "" || cmbSearchCategory.SelectedItem.Text != "" || cmbSearchHazardCategory.SelectedItem.Text != "")
    {
         RegisterDOMReadyScript("alert message", "alert('Message Here');"); 
    }

Hope Its Helpful.

if not using Update panel then use below code

Page.ClientScript.RegisterStartupScript(this.GetType(),"Msg",alert("Javascript message"), true);

else

ScriptManager.RegisterStartupScript(this.GetType(),"Msg",alert("Javascript message"), true);

try the following code inside the if :

if (txtSearchName.Text != "" || cmbSearchOaO.SelectedItem.Text != "" || cmbVessel.SelectedItem.Text != "" || cmbSearchApplicationType.SelectedItem.Text != "" || cmbSearchHull.SelectedItem.Text != "" || cmbSearchCategory.SelectedItem.Text != "" || cmbSearchHazardCategory.SelectedItem.Text != "")
{
    ScriptManager.RegisterStartupScript(this, this.GetType(), "err", "alert('Message you want write');", true);
}

RegisterStartupScript has 5 parameters we used. this :: referers to the control, this.GetType() is used to get the type of control, err is a string key. alert('mesage') whatever you want to write, true :: do you want to add script block in code or not if yes the true otherwise false

Hope this will work for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM