响应.重定向代理怪异 [英] Response.Redirect acting wierd

查看:62
本文介绍了响应.重定向代理怪异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Login.aspx页面,其中包含一个文本框和一个位于UpdatePanel中的按钮.我已将JS函数连接到文本框的onkeydown事件,以便如果用户点击Enter,它将单击按钮

I have a login.aspx page with a textbox and button inside an UpdatePanel. I''ve wired a JS function to the textbox''s onkeydown event so that if the user hits enter it will click the button

function clickButton(button)
{
    if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
    {
        document.getElementById(button).click();

        return false;
    }
    else
    {
        return true;
    }
}


这有效(在服务器上触发按钮的click事件).单击事件检查文本框中的值,然后执行Response.Redirect("Default.aspx");当该行执行Login.aspx的Page_Load事件时,将再次触发该事件.我已经完成了几次,看不到为什么.但是,如果用户用鼠标单击该按钮,则一切正常.我将断点放在Default的Page_Load中,但它从未被击中,所以我很确定页面不会重定向回Login.

我显然做错了事,但似乎无法弄清楚这是什么或如何解决.我以前使用过js函数,没有遇到任何问题.

任何帮助将不胜感激.


this works(the button''s click event fires on the server). The click event checks the value in the textbox then does Response.Redirect("Default.aspx"); when that line executes the Login.aspx''s Page_Load event fires again. I''ve stepped through this a few times and cant see why. However if a user clicks the button with the mouse everything works perfectly. I put breakpoint in Default''s Page_Load and it never got hit so i''m pretty sure it isnt that page redirecting back to Login.

I''m obviously doing something wrong, but cant seem to figure out what it is or how to fix it. I''ve use the js function before and havent had any problems.

Any help would be appreciated.

推荐答案

将defaultButton属性添加到表单中时,当我再次尝试它.早些时候我没有诉诸于JS函数.我不确定是什么原因使它现在可以工作,所以我想弄清楚.如果我愿意,我将更新问题.感谢您的帮助.
Adding the defaultButton property to the form worked when i tried it again. It hadnt earlier to i resorted to the JS function. I''m not sure what changed that made it work now, i''m trying to figure it out. If i do i''ll update the question. Thanks for the help.


尝试以下代码,-
函数checkKeycode(e){
var keycode;
如果(window.event)
{keycode = window.event.keyCode;
}
否则,如果(e)
{
键码= e.which;
}

如果(键码== 13)
{
__doPostBack(''btnSubmit'',");
}
}

& lt//script& gt;

或者,
确保断点在按钮单击事件中正常工作
Try with following code,-
function checkKeycode(e) {
var keycode;
if (window.event)
{ keycode = window.event.keyCode;
}
else if (e)
{
keycode = e.which;
}

if (keycode == 13)
{
__doPostBack(''btnSubmit'', "");
}
}

</script>

or,
Make sure breakpoint is working in button click event


尝试将按钮放在更新面板之外,看看它是否有效...
Try placing your button outside the update panel and see whether it works...


这篇关于响应.重定向代理怪异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆