views:

46

answers:

2

Hi, 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;


}
+1  A: 

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?

Ladislav Mrnka
I want to post the data in the url (with the query string) to another site to display some information as a result by using the query string values. The other site is inaccessible to me, i can only send data that way.
Tobby
Post data to different site? In that case you probably need HTML form and post to some page in that site.
Ladislav Mrnka
ImageButton will post only to your site. Or you can use HyperLink if the other side accept request as HTTP GET.
Ladislav Mrnka
+1  A: 

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

Response.Redirect(theURL);
Bisolu Adekoya
Response.Redirect merely redirects, the data needed arent posted to the target aspx page. But it works on a 2nd button click.
Tobby
If the data is in the QueryString, there is no reason why you cannot use Response.Redirect.
Jason Berkan