1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2005
    Rep Power

    ASP.NET : PostBack not firing after Javascript function.

    Hello, and thanks in advance for looking at my question.

    I'm new to .NET development (moving from ASP classic) so forgive me if my terminology is off.

    I have a data grid that allows a user to edit rows of data, not unlike a spreadsheet. One of the columns has a checkbox. When the user clicks a button called btnSaveAll, the page posts-back and deletes the proper (checked) records. This works fine.

    I am adding functionality to ask the user for confirmation before the postback. I did this by adding this code to my page in the Page_Load sub :

    btnSaveAll.Attributes.Add("onclick", "return confirmDelete (this.form);")

    confirmDelete is a Javascript function that looks like so :

    function confirmDelete(frm){
    for (i=0; i<frm.length; i++)
    if (frm.elements[i].name.indexOf("chkToDelete") !=-1)
    return confirm ('Are you sure you want to delete your selection(s)?')

    Now, this works just dandy, the user selects the rows to delete and clicks btnSaveAll, the JavaScript fires and asks for confirmation, but then the page doesn't post back.

    The button in the code on the client appears as such:

    <input language="javascript" onclick="return confirmDelete (this.form); __doPostBack('btnSAveAll','')" name="btnSAveAll" id="btnSAveAll" type="button" value="Save All" class="MainText" />

    Now, from that we can see that both confrimDelete and __doPostBack are called in the onClick event, and confirmDelete seams to work just fine, but __doPostBack never fires.

    Now, if I comment out the Attributes.Add line in my Page_Load sub, everything works fine again, just no confirmation popup.

    I am at a loss as to why. I have been working on this for far too long (2 or 3 hours) and my boss is getting just a bit antsy about it.

    Unfortuantely I cannot send all my code as there's just too damn much of it, but I can furnish anthing else you think might help. Any help is greatly appreciated.
  2. #2
  3. Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Dec 2003
    Rep Power

    Thumbs up Hey You should register the script in Page_Load..

    Hey You should register the script in Page_Load..
    Then it will work..
    And also in JavaScript make one variable and assign it to your Confirm(); function.
    If that variable=ok then this.form.submit();

    ASP.NET Geeks
    Visit this group

Similar Threads

  1. javascript function limitations?
    By darsunt in forum ASP Development
    Replies: 4
    Last Post: April 22nd, 2005, 06:43 PM
  2. Need large javascript function
    By darsunt in forum HTML, JavaScript And CSS Help
    Replies: 5
    Last Post: April 22nd, 2005, 02:19 PM
  3. Calling another function from within a javascript
    By ikiloh in forum ASP Development
    Replies: 1
    Last Post: October 8th, 2004, 01:39 PM
  4. Using Javascript in ASP.NET
    By udayjdesai in forum .NET Development
    Replies: 4
    Last Post: December 13th, 2003, 01:30 AM
  5. Problem passing a value to an asp.net page
    By PalmDrac in forum .NET Development
    Replies: 4
    Last Post: March 5th, 2003, 02:02 AM

IMN logo majestic logo threadwatch logo seochat tools logo