.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Javascript alert vs postback

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net

My aim is to not cause a postback if a session var does not equal a certain value when the user clicks the DELETE button. But this causes a postback regardless after the javascript alert is invoked.

I guess I need another logical scenario?




View Complete Post

More Related Resource Links

Font on Page Becomes Bold After Javascript Alert -- Why?

In .Net 3.5   I have a web page that has several checkboxes, text boxes, dropdown boxes etc on it.  When a user clicks on the search button, I run some basic validation on the page. If any validation fails, I invoke a javascript alert letting them know what they did wrong and I return them to the page. However, when the page reloads, all of the text on the page is now larger and bold, even the text inside the menu and which resides in a master page.  I removed every instance of the word "bold" from the project but it still becomes bold after the alert fires. Any idea what could be causing this to happen?  It shouldnt matter but here is a sample of the alert I use: Response.Write("<script language='javascript'>alert('You must check at least one column to display');</script>") Any help is greatly appreciated. thanks

Client Javascript runs, but then page errors out when clicking on a control that uses postback

Using this script on a button click <script language="javascript"> function printdiv(printpage) { var headstr = "<html><head><title></title></head><body>"; var footstr = "</body>"; var newstr = document.all.item(printpage).innerHTML; var oldstr = document.body.innerHTML; document.body.innerHTML = headstr + newstr + footstr; window.print(); document.body.innerHTML = oldstr; return false; } </script> After it is done, I can't click on my calendar control.  I was hoping to add somethign that would force a refresh in the script, but nothing I do works. Any thoughts?  Thanks! 

ListSearchExtender causing double postback when alert() or confirm() is called within PageRequestMan

This is a weird one.   I'm trying to implement a confirmation dialog before an async postback.  The idea is to use the JavaScript confirm() function to allow the user to cancel the postback.  I'm implementing it this way because my page has a bunch of different controls that might trigger an async postback inside an UpdatePanel.  Some of these are Ajax Control Toolkit controls like the ComboBox.  Rather than trying to trap the DOM event that triggers postback for each of these controls, it's easier to write one function and attach it to the client side initializeRequest event of the PageRequestManager, calling set_Cancel(true) or abortPostBack() if the user does not confirm.  This function can also be a central place to undo any changes if the user does not confirm.The problem is that the act of popping up the confirm dialog causes the UpdatePanel to postback twice, but only when the triggering control is a DropDownList (with AutoPostBack enabled, of course) with a ListSearchExtender.  If I replace the confirm() with alert(), the same thing happens.  If I comment out the alert, the problem goes away.  Below is a stripped-down page to reproduce the issue.  (I tested with IE 8/FF 3.5, and also tried both the new ASP.NET Ajax Library Beta 0911 and the old AJAX Control Toolkit Version 3.0.30930.)<%@ Page Language

Gridview attribute changed by javascript is lost on postback

I have a gridview control that extends the default gridview.  I have added an attribute called "hiddenSelectedValues" to to the gridview during the "PreRender" event and I have a private variable that points to the value of that attribute. I have some javascript code that modifies the value of this attribute based on the user checking or unchecking checkboxes in the grid.  I have confirmed that the javascript is indeed modifying the value of the "hiddenSelectedValues" attribute by using Firebug to see the change as it happens. However, once a postback occurs, the grid looses the updated value of this attribute and I am unable to reference get the updated value on the server side. How do I keep the value of an attribute changed by javascript on postback?

Delay Postback in Javascript


How to Delay Postback in Asp.net Using Javascript: Please Post Some Sample Code

I have a Button Need to Show a Timer Of 10 Seconds and Then Postback. This will happen on Button CLick

So How can i Accomplished that ??

Javascript Alert after closing a modalpopup



I have a linkbutton 'Forgot Password?' in my login page. On click of the link button  a modal popup will open . In that user has to give his username.

If the username doesnot exists  i want to show an alert 'Usename doesnot ' exists. 

Since the checking for the existenance of the username is on click of the button submit which is inside the modal popup, i can show the alert using the code

Page.ClientScript.RegisterStartupScript(...) . But I want something different

I want to call the javascript function after the maodal popup extender is closed

Please help me.



prevent postback javascript problem


i have the following example but i get error on GetPostBackEventReference line

value of tpe ...button cannot be converted to....

second question:where should i put this code? do i need just this code and nothing else

how should i for example delay for 20 seconds??

Dim sb As New System.Text.StringBuilder()
            sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
            sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
            sb.Append("this.value = 'Please wait...';")
            sb.Append("this.disabled = true;")
            Me.btnAddPhotoComment.Attributes.Add("onclick", sb.ToString())



How can i safe value of variables in javascript code in PostBack event?


Hi Experts.

I need to define some Boolean variables in my javascript code and use them  when  the any onfocusout methods of controls  is fired. Like this:


            Var is_ValidateTextBox1 = false;

            Var is_ValidateTextBox2 = false;

            Var is_ValidateTextBox3 = false;

Function focusout_TextBox1()

{ValidateTextBox1 = true; }


When onfocusout of TextBox1 is fire, I want to set  " is_ValidationTextBox1=true;".  But when the post back is fired from the form, the variable reset to false because the line of defining the "Var is_ValidateTextBox1 = false;" is run again in post back!

Now how can I to solve this problem? How can i safe value of variables in javascript code in PostBack event?

With Regards. Mojtaba

How do you get a textbox/input or a javascript to postback?


I am using a Yahoo UI dual slider.  The dual slider changes values based on what you slide.  It uses javascript and sends this value back to a Input type="text" textbox. 

I want to be able to do a automatic postback and call the server function "protected void zoom(object sender, EventArgs e)"  each time the slider value changes.

So what I did was:

<asp:TextBox type="text" id="demo_from"  runat="server"
OnTextChanged="Zoom" AutoPostBack="true">

But the problem is, it WILL not fire the server-side event unless I manually click the textbox and press "ENTER".  Then the event will fire (during debug).

So how can I get the event to auto-fire each time the slider value changes?


javascript alert window when dropdown field is selected,



is there a way..where an alert window prompts up to remind the user to select a checkbox when one field in dropdown is selected..for example

there is a dropdown field(Status)  which contains (Tobe confirmed, confirmed and rejected ), when confirmed is chosen..an alert window prompts up reminding the user to select a checkbox(send email) - Yes or No. It is not compulsory for the user to select the checkbox, but if Yes is chosen, the workflow will send an email

ASP.Net Postback using javascript for Radio button list


Hi There,

My current structure:

1. An asp.net radio-button list with autopostback = true. The radio-button list has 2 items - Yes and No.

2. An asp panel that has 2 textbox.

Current behaviour:

When the user clicks on the radio-button list (i.e. Yes), the panel is made visible.

My clients wants the same functionality without the page refresh (i.e. the postback). I tried looking through a lot of forums and articles and couldn't find the any article that would show an example for drop-down list or radio-button list.

Any help is much appreciated..!


dynamic javascript of an .ascx control not updating on client upon async postback


I have a confusing state issue. I found a way around it, but I would like to know why this is happening. First of all, I am using .NET 3.5 and that can't change right now (an easy fix may be the fixed ID capabilities of .NET 4.0).

Type csType = this.GetType();
ClientScriptManager cs = Page.ClientScript;
string jScriptBlockName = "SignUpSignInNameAvailabilityScript";
if (!cs.IsClientScriptBlockRegistered(csType, jScriptBlockName))
{   //NOTE: verified code always enters this
    StringBuilder cstext2 = new StringBuilder();
    cstext2.Append("function GetSignUpSignInNameAvailabilityMessage() { var id = '"
          + CreateUserWizardStep1.ContentTemplateContainer.FindControl("iSignUpSignInNameAvailabilityMessage").ClientID
          + "'; alert(id); return id; }");
    cs.RegisterClientScriptBlock(csType, jScriptBlockName, cstext2.ToString(), true);

This code is in Page_Load of an ascx. The same control is drawn on two separate postbacks of an UpdatePanel in different places of the page thus giving them different client IDs. The code works correctly on the first refresh of web browser; but after UpdatePanel

javascript script works with alert() and does not fully work without it



Im facing the following problem i have a gridview that i insert an OnClick event to each row in order to be able to click on a row and selecting that row (change the color of the selected row e.tc) my javascript works fine when i have an alert when i remove the alert

then i see the color of the row changing as i click it but then when i move the mouse the color changes back to normal i still get the id of the row since i have a textbox where i put the id content of the e.row.cell[0] value .

I searched the web and i found out that its something to do with ajax and asychronous calls here is the code if the alert is enabled everything works fine this function is called from .c#

protected void GrdEntal_RowDataBound(object sender, GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.DataRow)

                e.Row.Attributes.Add("onclick", "javascript:getID('" + e.Row.Cells[0].Text + "', '" + e.Row.ClientID + "', '

how to do a javascript alert from a another public class


I'm using the ReportGenerator.cs class and this class is referenced from the actual calling page Default.aspx and Default.aspx.cs

using GeneraReport;

in the Default.aspx.cs

and the code in GenerateReport.cs:

namespace GeneraReport
    public class ReportGenerator

This namespace has no reference to Page

However I need to be able to do the following in the public class:

      if (dt.Rows.Count == 0)
                        string Script = "";
                        Script += "<script language=JavaScript id='NoRows'>";
                        Script += "alert('No Rows Found in Query');</script>";

javascript alert msg


I have an app with many pages where in the page load event I check for a session variable   Session("usr") being populated or not.

If it is not I then use the following few lines of code to initiate a JS function that is loaded into each page via an include statement.

It works fine, except for this one page.  Any ideas:


Code Behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim bldvw As base = New base

Dim cm As ClientScriptManager = Page.ClientScript

Dim cbReference As String

 'see if session has timed out

If bldvw.validateUsr = 0 Then

If (Not ClientScript.IsStartupScriptRegistered("")) Then

cm.RegisterClientScriptBlock(Me.GetType(), "alert", "logout();", True)  

' above line is actually hit each time, but the alert msg never comes up

End If

End If

<-- more code  irrelevant to this task--->

end sub

Public Function validateUsr() As Integer

If Session("usr") = "" Or Session("usr") = Nothing Then

validateUsr = 0


validateUsr = 1

End If

Return validateUsr

End Function




how to use javascript message("alert) in System.Web.IHttpHandler


hello every one i using system web handler when System.Web.IHttpHandler

           save the record than how can show message "Record is saved"

multiple line javascript alert in codebehind c#


I'm trying to put line breaks in my alert that's in a Response.Write like this:


Response.Write("<script>alert('" + dr["display_title"].ToString() + "\n is " + dr["display_title"].ToString().Length + " characters. Title cannot exceed 100 characters. Please limit all titles to 100 characters or less.')</script>");


with the \n  character, but instead of the alert showing up on multiple lines in the dialog box, the alert itself is breaking up into multiple lines like this:

alert('some text

more text

more text')


How would I get this to work correctly? Thanks

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend