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

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

Bug? OnClick event prevents postback on CommandField BUTTONs

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

This has been asked a few times before but I can't find a definitive answer.  If I have a delete button in a commandField and programmatically add an OnClick javascript confirm, then the page never posts back after the dialog appears.  When using the same approach using a LINKBUTTON, everything works perfectly.  Is there any way to get this functionality to work using BUTTONs??

This works fine (using a LINKBUTTON):

<asp:CommandField Visible="false" ItemStyle-Width="150" ButtonType="Link" ShowDeleteButton="true" DeleteText="Delete" />

Sub gvRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.RowState = DataControlRowState.Normal OrElse e.Row.RowState = DataControlRowState.Alternate Then
e.Row.RowState = 0 OrElse e.Row.RowState = 1 Th

View Complete Post

More Related Resource Links

Keeping onclick event after postback


We have a 3 tab setup using css and the following javascript, if im on tab2 or tab3 and i submit the form within that tab, when the page posts and reloads, the tab defaults to tab1

Is there anyway to update this logic to keep the viewstate or would i be better off going with the tab control for our page?

        function goSearchOption(theoption) {
            for (var i = 1; i <= 3; i = i + 1) {
                if (i != theoption) {
                    document.getElementById('searchOption' + i).style.display = "none";
                    document.getElementById('nav' + i).setAttribute("class", "searchnav");
                else {
                    document.getElementById('searchOption' + i).style.display = "block";
                    document.getElementById('nav' + i).setAttribute("class", "searchnavHL");



jquery click event doesn't fire after postback anymore

Hello there,I have a small website where I want to display a confirmation dialog after clicking on a button.When you click the confirmButton the dialog appears. Then you can choose between Yes or No to either continue with the PostBack or to return.Problem: The first time you get into the site all works fine. But after you click Yes to continue with the PostBack, no click event will be triggered anymore.Here is some code.<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <script type="text/javascript"> function loadConfirmDialog() { //Dialog configurieren jQuery('#confirmDialog').dialog({ autoOpen: false, width: 400, modal: true, resizable: false }); //Dialog öffnen jQuery('#confirmButton').bind('click', function () { jQuery('#confirmDialog').dialog('open'); return false; }); //Postback ausführen jQuery('#continueButton').bind('click', function () { jQuery('#confrimDialog').dialog('destroy'); __doPostBack('confirmButton', ''); }); //Postback abbrechen jQuery('#cancel

Calling a button's click event from another buttons click event

I have a button that checks the users serial number entry in a web form and a button that subits the page.  But if the user does not click the checkbutton  I want to  fire the check click event  from the pages submit click event.  Is this possible.  In my submit click event I call this Me.cmdCheck_Click(sender,e) though it does not seem to be firing the click event is there something that I am doing wrong?  

Treeview node to add onclick event to download files

 Hi, I would like to know how to add onclick evend to a TreeNode so that the file can be downloaded.   How can I implement below sample code to a TreeNode? <a href="#" onclick="popup('/directory1/Somefile.doc'); return false;" target="download"> Somefile </a> <script language="javascript"> function popup(url) { popWin = window.parent.open(url, 'popWindow', 'height=900, width=900, toolbar=no, menubar=yes, scrollbars=yes, titlebar=no, resizable=yes,location=0, directories=no, status=no'); } </script> I have TreeNodePopulate event to populate nodes like this: protected void DocRepository_TreeNodePopulate(object sender, TreeNodeEventArgs e) { .... String[] files = Directory.GetFiles(fullPath); foreach(String file in files) { TreeNode newNode  = new TreeNode(Path.GetFileName(file), Path.GetFileName(file)); node.ChildNodes.Add(newNode); } }   Thank you in advance.              

Row Command Event (Grid View) and PostBack

I have a grid view with a number of columns in Page1.aspx.The last column is a template field with a button. On it's row command event,The control is transferred to Page2.aspx.  Initially, I had not put the PostBack property in Page1.aspx and when I used breakpoint in the RowCommand event the control never entered inside the event.However,it worked fine once I did the postback property. Can anyone explain why did this happen?  I have a grid view with a number of columns in Page1.aspx.The last column is a template field with a button.On it's row command event,The control is transferred to Page2.aspx. Initially, I had not put the PostBack property in Page1.aspx and when I used breakpoint in the RowCommand event the control never entered inside the event.However,it worked fine once I did the postback property.Can anyone explain why did this happen?  

asp:Button inside a SharePoint Dataview's Rows with onclick event does not call C# function. Pull i

asp:Button inside SharePoint Dataview Rows with onclick event does not call C# function. Pull it out of Dataview and works fine. I have a ASP.NET Button I've placed inside a SharePoint  DataView's rows with an onclick event pointing to C# function block inside my page. The page refreshes when I click on them, but it's not hitting that code block. If I move the button to outside the dataview and make the ID fixed, the code works beautifully. what's up with that? the button in the Dataview: td class="ms-vb" style="width: 70px"><asp:Button runat="server" Text="Delete" id="Delete{@ID}" CommandArgument="{@FileRef}" OnClick="DeleteDoc"/> </td> my C# onclick handler (inline C# on the page) void DeleteDoc(object sender, EventArgs e) { Button b = sender as Button; .. more code The buttons are rendered and they look like this: input type="submit" name="ctl00$PlaceHolderMain$g_08acadfd_957b_4112_a426_cc7c81991c1e$Delete1" value="Delete" id="ctl00_PlaceHolderMain_g_08acadfd_957b_4112_a426_cc7c81991c1e_Delete1" Thie code block in inline and I'm working from SharePoint Designer. Not sure how I can troubleshoot this.  Am I missing something here, maybe I need to add an Itemtemplate or something like we need to in the ASP.N

URL Routing + PostBack not firing BeginRequest event


hi all,

we are having some weird issues with URL Routing in ASP.NET 3.5. 

We have a search box that does a search and redirects to a routed URL.

 When we search for the first time (aka Press a button that forces a postback) everythign works as expected.  we get:

1. BeginRequest event.

2. Determines Route

3. Calls Routehandler to match the route item to the actual destination page

4. Routes the url appropriately.

After you do one search successfully and try again it fails to call the BeginRequest event.  Because of this the routing data never gets called and so the url is never routed to its correct destination.   What is weirder still if we append a "/" (trailing slash) to the url after the initial postback it DOES work properly again. 

So our search route looks like this


entering a term and pressing the SEARCH button would yield a result url like this:



Going back (after 1 successful search) you then need to use this url or else BeginRequest will never fire:

mydomain.com/Search/ < (note the extra "/" at the end)


Anyone have an idea a

AjaxControlToolkit TextBoxWatermarkExtender fires TextChanged Event on every postback


I haven't been able to find anything on the net about this yet. A project that used to work fine all of a sudden started having trouble with a couple users. The TextBoxWatermarkExtenders for these users are now always firing the TextChanged event of the textboxes they are assigned to for every postback. I don't think this is what they are supposed to do. They didn't use to do this. Has anyone else experienced this? I can add code to ignore these unintentional events, but I would like to know why all of a sudden the change in behavior.

Any information about this would be greatly appreciated.


How can I process multiple buttons with one click event?


I want to dynamically build a table where each of the first three cells may or may not contain an image.  If a cell contains an image, it may or may not contain a radio button.  The last cell contains a button or link button.  I want all the buttons to be handled by the same click event.  The number of rows, which cells will have an image, and which cells will have a radio button is not known at design time.  Finally, the images are displayed using the better image control.

I'm trying to get this to work usinging a repeater, but at the moment I can't get the radio button checked propety to change from the default value.  I'm using an arraylist as a datasource.  I thought of using a gridview, but I don't know how to add a radio button and a better image control to a cell. 

I've gone round and round with this thing. Each time after a lot of work I find there is something I can;t get working.  Is there a reasonable solution for this? 

I'm back to wanting to build a table, but how do I handle the buttons?

Calling Button,s onclick event in javascript code


 Hi Experts.

I have a Button control in webpage.

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="test()"/>

When i click on button, i want to check some conditions

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

Prevent postback but need to trigger an event



Is there a way that to prevent a postback on button click? But at the same time, when click on the button, it should be able to trigger a function.

I want sometime like Onclick = "runFunction", but to disable the postback.


Button OnClick event not working.


Hi folks,

I am having trouble with two buttons on a page. I dragged them on to the page and then double- clicked each of them in order to create the OnClick events.

I added my code to the events, but when I click the buttons, their respective events aren't being called.

I am very confused!

Any help is appreciated, thanks!

My .aspx code:

<asp:Button ID="Button3" runat="server" Text="Accept" CausesValidation="true" onclick="Button3_Click" />
        <asp:Button ID="Button4" runat="server" Text="Reject" CausesValidation="true" onclick="Button4_Click" />

My Code behind:

protected void Button3_Click(object sender, EventArgs e)
        int id = int.Parse(queryString);

        #region LiveDatabase
        //string connection = ConfigurationManager.ConnectionStrings["LiveDatabase"].ToString();

        #region MySqlDatabase
        string connection = ConfigurationManager.ConnectionStrings["MySqlDatabase"].ToString();

        MySql.Data.MySqlClient.MySqlConnection MyConn = new MySql.Data.MySqlClient.MySqlConnection(connection);

        string query = "UPDATE p

Why is there a postback with every timer event?


The handler for my timer event checks the status of a table in my database.  If there is any change, it causes a redirection of the web page to occur so that the change will be displayed.  But, when the timer event handler ends without any change, it still causes the page to be re-posted with every tick.  Why?  How can I conclude each timer event without causing a postback, which interferes with the user's ability to scroll down and view the entire page?



asp:button OnClick/Postback not working in IE7 & IE8


 I have a content page that has a form in it. The problem that I am having is that I get no response from the submit button for when clicking on it in IE 7 and 8. I have also siccessfully tested it in Firefox, Chrome and Safari.

This seems like a fairly common problem but I have yet to find a solution that works. I found some posts that suggested that there might be a problem with the aspnet_client folder so I ran aspnet_regiis -i and restarted IIS. I even when so far as to reinstall the asp.net framework and IIS. No love there.

I have verified that I have only one form tag in my master page also.

I also tried messing with the buttons UseSubmitBehavior, but that started up a whole mess of other problems like form field vaules not being posted.

Maybe there is something simple I've been missing becaue I've been looking at it too long ;) Fresh eyes would be appreciated.

Here is my master page:

<%@ Master Language="C#" %>
<script runat="server">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

asp:button Click event (inside a repeater) lost on postback.


 I have been writing C# code for about 3 years now and have never had this happen.

I am using an asp:repeater (inside an update panel):

<asp:Repeater runat="server" ID="rptRedFolderDocs" OnItemDataBound="rptDataBound">

inside the repeater I have a button with a click event with server side code.

When the page loads, the repeater is databound to a datatable popuplated from SQL connection.  The repeater is NOT bound on postback. I wanted the data to persist.

When the button is click

Using an onclick event to create a timestamp


I have a web site with a button onclick event and when a user clicks on the button I want that to create a timestamp event in my SQL server. I have the following default.aspx.vb code:

Imports System.Data.SqlClient
Imports System.Data

Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    End Sub
    Public Sub InsertRow()
        Dim myConnectionString As String = "Initial Catalog=mdr;Data Source=xxxxxx;uid=xxxx;password=xxxxxxx;"

        Dim myConnection As New SqlConnection(myConnectionString)
        Dim commandText As String = "insert into Exceptions (employeenumber, exceptiondate, starttime, endtime, duration, code, approvedby)" & _
        " values (@employeenumber, @exceptiondate, @starttime, @endtime, @duration,@code, @approvedby)"

        Using connection As New SqlConnection(myConnectionString)
            Dim command As New SqlCommand(commandText, connection)

            command.Parameters.Add("@employeenumber", SqlDbType.VarChar)
            command.Parameters("@employeenumber").Value = OperatorDropdown.SelectedItem.Text

            command.Parameters.Add("@exceptiondate", SqlDbType.DateTime)
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