Is it possible to make a button postback twice, or postback on hover?

Last post 09-03-2008 3:19 PM by cdell. 6 replies.

Sort Posts:

  • Is it possible to make a button postback twice, or postback on hover?

    09-03-2008, 10:11 AM
    • Contributor
      2,628 point Contributor
    • darkknight187
    • Member since 09-14-2006, 4:35 AM
    • Bothell, Washington
    • Posts 1,016

    Here's the basic scenerio.
    I have a search form that works perfectly 95% of the time.

    If the user enters data into cityTB and stateTB,
    (both are set to auto postback to an update panel)
    that triggers an event to get the zipcode for that area. Woks great

    Now the issue lies if the user decides to search for a second city
    and just clicks straight from typing in cityTB to the button to find listings.

    The postback is triggered, but it gets the new zip at the same time of retrieving listings.
    Which displays the previous search, unless the button is clicked twice.

    If you would like an actual demo, do a search for frisco in texas with a search radius of 10 miles.
    Click Refine Search, you'll get your results, now change the city to dallas, and click the button without moving out of the cityTB.
    You'll get the same results, unless you tabbed out, or clicked out of the cityTB.
    Click the button again making no changes this time, and now you see your search for dallas.
    www.detelli.com/results.aspx

     

    So to fix this, I would like to make the button postback get the new zipcode, and then postback listings.
    I'm thinking some sort of onclick event, but I don't know.
    Or set a onhover postback should work, I just need a fraction of a second to process the new zip.

    Any thoughts?

    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.
  • Re: Is it possible to make a button postback twice, or postback on hover?

    09-03-2008, 11:40 AM
    • Member
      171 point Member
    • cdell
    • Member since 04-04-2008, 2:43 PM
    • UF
    • Posts 186

    So are you using the "TextChanged" action to change the zipcode?

    On the button click, couldn't you use a

    try

    {  code to change zip   }

    finally

    {   code to search listings    }

    that way it would change the zip first?

  • Re: Is it possible to make a button postback twice, or postback on hover?

    09-03-2008, 1:56 PM
    • Member
      177 point Member
    • fatthippo
    • Member since 08-30-2006, 2:52 PM
    • Posts 170

    >>Is it possible to make a button postback twice, or postback on hover?

    In the page load event you can add this, which would execute a js function in addition to whatever else you were doing.

    myButton.Attributes.Add("onmouseover", "myFunction()");

    You can make a server side call with javascript through a PageMethod Request. This will execute along with whatever else the button is doing.

  • Re: Is it possible to make a button postback twice, or postback on hover?

    09-03-2008, 2:42 PM
    • Contributor
      2,628 point Contributor
    • darkknight187
    • Member since 09-14-2006, 4:35 AM
    • Bothell, Washington
    • Posts 1,016

    cdell:

    finally
    {   code to search listings    }

    The code to search is not on the codebehind, but out of an objectDatasource on the aspx page.
    So how could I write the finally?

     

    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.
  • Re: Is it possible to make a button postback twice, or postback on hover?

    09-03-2008, 2:49 PM
    • Member
      171 point Member
    • cdell
    • Member since 04-04-2008, 2:43 PM
    • UF
    • Posts 186

    The few searches I use are in the code behind, with a SELECT statement populating a gridview, or something of the like.  So i change the parameters of the select statement depending on user inputs.  Sorry if this doesn't help. 

  • Re: Is it possible to make a button postback twice, or postback on hover?

    09-03-2008, 3:03 PM
    • Contributor
      2,628 point Contributor
    • darkknight187
    • Member since 09-14-2006, 4:35 AM
    • Bothell, Washington
    • Posts 1,016

    Maybe I'm going about this the wrong way.

    Maybe I should just add the control parameter in codebehind,
    that way I could specify which TB to look for zipcode.

    Here's my SelectParameter:

    <asp:ControlParameter Name="ZipCode" DefaultValue="" Type="String" ControlID="ZipCodeQueryTB">
    </asp:ControlParameter

    How could I add the above in a page_load event? 

    I was thinking something like this, but not right.

    AdSearchDataSource.SelectParameters.Add(ControlParameter)

    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.
  • Re: Is it possible to make a button postback twice, or postback on hover?

    09-03-2008, 3:19 PM
    Answer
    • Member
      171 point Member
    • cdell
    • Member since 04-04-2008, 2:43 PM
    • UF
    • Posts 186

    I tried to do that once, but didn't figure it out quickly and just switched to all code-behind (i.e. SELECT * from Customers WHERE zip = @zip, and then did a cmd.parameters.addwithvalue) but check this thread, it may help you do what you're trying to do.  http://forums.asp.net/t/1208578.aspx

     You may have to create a parameter, and then do the AdSearchDataSource.SelectParameters.Add(ControlParameter)

     

            SqlParameter ControlParameter= new SqlParameter();
            ControlParameter.ParameterName = "@Zip";
            ControlParameter.Value = txtZipCode;

     I'm not sure if I'm helping you at this point, as I've never done things exactly the way you're doing them before. 

    EDIT: 

    I checked my code and its something like this: 

                SqlCommand cmdSearch = new SqlCommand("SELECT * from Table where Zip = @Zip");
                cmdSearch.Parameters.AddWithValue("@Zip", txtZip.ToString());
                datasource.SelectCommand = cmdSearch;
     
Page 1 of 1 (7 items)