Solved

javascript buton click

Posted on 2009-05-15
4
262 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
  • 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now