ScriptManager.RegisterStartUpScript(......)不工作 [英] ScriptManager.RegisterStartUpScript(...) not working

查看:416
本文介绍了ScriptManager.RegisterStartUpScript(......)不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这个命令,因为我开始我的 ImageButton_Click 事件新的项目,它的工作十全十美页,我使用这样的:我首先检查如果有一个字段为空,如果是的话,我发送此警报

I've used this command since I start my new project on ImageButton_Click Event, and it's working perfect in every page that I'm using this: I first, check if there's a field empty if yes then I send this alert.

ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('No Empty fields are allowed.');", true);  

我在做什么在这里:我有2 文本框我输入两个日期,这些日期被用来填补我的的ReportViewer ,但在此之前它会在的ReportViewer ,我检查它是否与否。

What I'm doing here: I have 2 textboxes that I type two dates, these dates are used to fill my reportviewer, but before it goes to the reportviewer, I check if it's empty or not.

在此页它的工作只是在我第一次preSS的按钮。我用了断点,它通过确定 throught我的条件如果,但它没有显示消息,为什么?结果
Button_Click事件全部code

In this page it's working only in the first time I press the button. I used breakpoint, and it's passing OK throught my conditional IF, but it's not showing the message... Why?
Full Code on a Button_Click Event:

 if (Txt_Dt_Final.Text == "" || Txt_Dt_Inicial.Text == "")
     {
        ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('No Empty fields are allowed.');", true);
        Txt_Dt_Inicial.Focus();
        return;
     }

更新结果
其实,在我preSS它的第一次,没有什么工作了......即使我输入一个有效的日期,它是不工作...我现在测试了它和,误差仅出现,如果错误hapens你第一次preSS的按钮。结果
例如:结果
如果我输入的日期确定,那么我的ReportViewer将返回我结果我的报告...然后我点击空文本框按钮时,它会触发错误,并告诉我的消息。如果我preSS再次它会正常工作!

UPDATE
Actually, after I press it by the first time, nothing works anymore... Even if I type a valid date, it is not working... I tested it now and, the error only appears, if the error hapens the first time you press the button.
e.g.:
If I type the dates OK, then my reportviewer will return me the result of my report... Then I click on the button with empty textboxes, it will fire the error and show me the message. If I press again it will work fine !

现在,如果我preSS与首次空字段的按钮,按钮不工作了!它刚刚复出工作,如果我刷新页面,为什么? o.O结果
我所有的其他网页正在完善。

Now, if I press the button with empty fields for the first time, the button does not work anymore ! It just back working if I refresh the page... Why ? o.O
All my others pages are working perfect.

推荐答案

您code应该工作,除非你有一个更新面板内你的ASP控制。
如果再使用这个代替。

Your code should work unless you have your ASP controls inside an update panel. If you do then use this instead.

ScriptManager.RegisterStartupScript(updatePanel,updatePanel.GetType()
                                                  , "alert", javaScript, true);

这篇关于ScriptManager.RegisterStartUpScript(......)不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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