我有一个文本框和一个图像按钮,如下所示
<asp:TextBox ID="myText" runat="server"></asp:TextBox>
<asp:ImageButton ID="btnExecute" runat="server" OnClick="btnExecute_Click" />现在我的问题来了,在Page_Load上有一些绑定..这些绑定进入了几十个控件和类,当它将要到达我的按钮的On_Click中的代码时,为时已晚。它会重定向到其他地方..我需要重定向到不同的页面,但它永远不会到达目的地,除非我以某种方式省略所有我不愿意做的事情。
所以,我想的解决方案是在图像按钮OnClientClick上使用Javascript,不幸的是我不是很擅长,希望你能帮助我。伪代码应该是这样的
if(the current url contains some page.aspx)
{
var value = get the value from myText;
then navigate to myotherpage?txtvalue=value;
}有没有人能帮我写下这个javascript,而不用详细解释我为什么要这样做?请
我真的很感激。
谢谢
发布于 2011-10-18 05:20:03
天真地将伪代码转换为javascript:
if (window.location.href.indexOf('page.aspx') > -1)
{
var value = document.getElementById('<%= myText.ClientID %>').value;
window.location.href = 'myotherpage?txtvalue=' + encodeURIComponent(value);
}发布于 2011-10-18 05:20:21
试试这个:
if (window.location.href.indexOf("page.aspx") != -1) {
var val = document.getElementById("myText").value;
window.location = "/myotherpage?txtvalue=" + encodeURIComponent(val);
}https://stackoverflow.com/questions/7799666
复制相似问题