Tobby
Tobby

Reputation: 13

Button clicked twice before postback

This is really driving me crazy having been on it for hours.

I have a url whose query strings are concatenated based on selected items on a form, I need to do a post to this url, but an imagebutton control has to be clicked for the post to occur. I put the PostBackUrl property of the imagebutton inside the event of the image button, hence causing it to be clicked twice before eventually posting the url... but i really need to click once but this aint working. I know why its clicking twice, tried calling the url with javascript but it wasnt working.

Below is the code. Please help me with code samples cos am still a newbie, kinda. Thanks

protected void searchImageButton_Click(object sender, ImageClickEventArgs e)
{
    returntype = tidRadioButtonList.SelectedItem.Value;

    dateDlabel = selddate1TextBox.Text.Trim();
    dateAlabel = seladate1TextBox.Text.Trim();

    depart = seldcity1DropDownList.SelectedItem.Value;
    arrive = selacity1DropDownList.SelectedItem.Value;

    flightclass = selcabinclassDropDownList.SelectedItem.Value;

    adult = seladultsDropDownList.SelectedItem.Text;
    child = selchildrenDropDownList.SelectedItem.Text;
    infant = selinfantsDropDownList.SelectedItem.Text;

    result = resultbyRadioButtonList.SelectedItem.Value;

    promos = promocodeTextBox.Text.Trim();


    string theURL = "http://yyy.xxx.com/CAB/SessionHandler.aspx?target=%2fCAB%2fIBE.aspx&pub=%2fng%2fEnglish&Tab=1&s=&h=?tid=" + returntype +
     "&seldcity1=" + depart.Trim() + "&selddate1=" + dateDlabel + "&selacity1=" + arrive.Trim() + "&seladate1=" + dateAlabel + "&selcabinclass=" + flightclass
      + "&seladults=" + adult + "&selchildren=" + child + "&selinfants=" + infant + "&resultby=" + result + "&promocode=" + promos;

    searchImageButton.PostBackUrl = theURL;


}

Upvotes: 1

Views: 1130

Answers (2)

Bisolu Adekoya
Bisolu Adekoya

Reputation: 21

Since you need to postback to another url, why not use

Response.Redirect(theURL);

Upvotes: 2

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364409

But you are saying ASP.NET to cause postback twice. PostBackUrl is special property for cross page postback but if you set it to the same page you will get the postback twice. First postback is common processing which occures because user clicks ImageButton. Second is initiated because you set up PostBackUrl. For your scenario you can't use ImageButton. Use HyperLink and place img inside the link. Btw. what are you trying to achieve with that code?

Upvotes: 2

Related Questions