Solved

javascript buton click

Posted on 2009-05-15
4
265 Views
Last Modified: 2012-05-07
I have a web modal dialog box that is retuning an argument to its parent window.  The return value is a stateabbreviation.  I iterate through a dropdownlist in javascript and select the appropriate state, then simulate a button click to post back the page.  That all works fine and the page is posted back  and my event handler for the button fires.
In the event handler I get data from the database and fill a grid view with data.  The problem is the grid view DOES NOT update when the page is returned to the client.  Below is the javascript code.  I have put a break point in the event handler for the button and it does fire off the grid view just does not update.  I thought that perhaps it was a cacheing issue so added the
<meta http-equiv="Pragma" content="no-cache" />
it the head section of the page.  
also below is the code in the event handler for the button. I look at the taxes data table in the GetTaxes() method and all the data is there!  

var rc = new Array(0,0);
        function showDialog(taxlevelid)
        {
            rc = window.showModalDialog("TaxDialog.aspx?lid=" + taxlevelid ,"","center:yes;dialogHeight:300px;dialogWidth:575px;resizable:no;status:yes;");
            if(rc[0] != null)
            {
                //
                
                var sl = document.getElementById("dropDownListState");
                for(i=0;i<sl.length;i++)
                {
                    if(sl.options[i].value==rc[1])
                    {
                        sl.selectedIndex=i;
                        break;
                    }
                }
                var gtb=document.getElementById("buttonGetTaxes");
                
                gtb.click();
                
                      }
   
        }
 
 protected void buttonGetTaxes_Click(object sender, EventArgs e)
    {
        GetTaxes();
 
        
    }
private void GetTaxes()
    {
        DataTable taxes = new DataTable();
        using (OracleHelper oHelper = new OracleHelper(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            oHelper.QueryCommandType = CommandType.StoredProcedure;
 
            OracleParameter p = new OracleParameter("In_State", dropDownListState.SelectedValue);
            oHelper.Parameters.Add(p);
 
            p = new OracleParameter("Out_Cursor", OracleType.Cursor);
            p.Direction = ParameterDirection.Output;
            oHelper.Parameters.Add(p);
 
            taxes = oHelper.GetDataTable("PKG_TAXLOOKUP_XRXX.READ_TAXES");
        }
 
        gridViewTaxTable.DataSource = taxes.DefaultView;
        gridViewTaxTable.DataBind();
        gridViewTaxTable.SelectedIndex = -1;
    }

Open in new window

0
Comment
Question by:marktoth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:wellhole
ID: 24398671
I believe you need to do the updating at the latest during the Load event. The click event occurs afterwards.
0
 
LVL 1

Author Comment

by:marktoth
ID: 24398814
ok that does work BUT I just noticed that page_load is called twice.  Why would it be called twice?  
That is the problem I think.  The first call to page_load happens, then the eventhandler is fired.  Another postback must happens and page_load is called AGAIN?
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24398899
Assuming I'm right about not changing the page after the Load event, any changes you make forces a postback to display your changes.
0
 
LVL 1

Accepted Solution

by:
marktoth earned 0 total points
ID: 24398946
No I solved the problem!  
On the click event for the button need to return false from the javascript so that the button itself did not cause a second postback event to be added to the events.  What actually happend was this senerio
1.  The javascript click event caused the postback, and the asp.net button control sent a postback to the server.
so
page_load is called
the event handler is called
then page_load is called again.
Then the page is fed back to the user hence with nothing in the gridview.

This was a good one and thanks for the help!!!!!!  It lead me to the right conclusion!
0

Featured Post

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
PHP Web Development 6 25
T-SQL and CLR parameter strings 9 26
Ruby or Python 7 56
Move files based on file names? 8 27
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

749 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