Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP Alert Box

Posted on 2014-02-10
1
Medium Priority
?
238 Views
Last Modified: 2014-05-29
Hi,

I am Using Alert Box for  Display Information.If I click on Ok in Alert, I want to set ISPostback property on page load. Can u plz give example how to do?

Here my alert box code :
Page.ClientScript.RegisterStartupScript(this.GetType(), "ALERT", "alert('Deleted Successfully');", true);

if I click Ok on Alert I want to execute below method.
protected override void CreateChildControls()
        {
                   
                if (Page.IsPostBack)
                {
                    display1();
                }
           
        }
0
Comment
Question by:mannevenu26
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 39847252
you will need these items, a hidden field:
<asp:HiddenField id="HiddenField1" runat="server" />

Open in new window


a javascript function:
<script type="text/javascript">
 //in javascript fist check for postback because it is registered on page load
function validate()
{
   var blnPostBack = '<%= Page.IsPostBack ? "true" : "false" %>';
   if (blnPostBack == 'true')
   {
       if(!confirm('Are you sure to submit?'))
       {
            document.getElementById('<%= HiddenField1.ClientID %>').value=0;
       }
    }
    else
    {
       document.getElementById('<%= HiddenField1.ClientID %>').value=1;
    }
} 
</script> [code]

finally, in your asp page: [code]protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
             ScriptManager.RegisterStartupScript(this, typeof(string), "alert", "validate();", true);
        }
      
    }

Open in new window

and your code changes to:
protected override void CreateChildControls()
{
         int result1=Convert.ToInt32(HiddenField1.Value);
         if (result1 == 1 && IsPostBack)
        {
        }
} 

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question