这让我疯狂了好几个小时。
我有一个网址,其查询字符串根据表单上的选定项目连接,我需要对此网址发帖,但必须单击图像按钮控件才能发布帖子。我将图像按钮的PostBackUrl属性放在图像按钮的事件中,因此在最终发布url之前将其单击两次...但我真的需要单击一次但是这样工作。我知道为什么它点击两次,尝试用javascript调用url但是它没有用。
以下是代码。请帮我处理代码样本cos还是新手,有点儿。感谢
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;
}
答案 0 :(得分:2)
但是你说ASP.NET会导致两次回发。 PostBackUrl是跨页回发的特殊属性,但如果将其设置为同一页面,则会获得两次回发。第一个回发是由于用户单击ImageButton而发生的常见处理。第二个是因为你设置了PostBackUrl而启动的。对于您的方案,您不能使用ImageButton。使用HyperLink并将img放在链接中。顺便说一句。您想用该代码实现什么目标?
答案 1 :(得分:2)
由于您需要回发到另一个网址,为什么不使用
Response.Redirect(theURL);