?
Solved

javascript buton click

Posted on 2009-05-15
4
Medium Priority
?
267 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

752 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