Solved

javascript buton click

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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 lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

785 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