验证字段,然后启动新窗口 [英] validate fields, then launch new window

查看:37
本文介绍了验证字段,然后启动新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨;


在页面中,当用户点击按钮时,我想验证所有

控件(在后面的代码中)然后,如果他们是好的,请单独留下页面

并启动一个带有新网址的新窗口。


这是我认为最好的方法 - 请告诉我是否有更好的



在我的代码中我验证了所有内容。

我然后设置一个标志作为会话变量。

然后我重新加载我所在的页面(我是重定向到页面还是

还有另一种方式?)。

当页面加载时,我查找会话变量并找到它,我会创建一个onload脚本。

onload脚本启动一个第二个窗口到另一个网址。 (有没有最好的

方式来执行此操作并指定网址,以便弹出窗口阻止程序不会阻止它?)

我有一个名为launch的javascript变量启动后我设置为true

重新加载我再也没有启动。


???


-

谢谢 - 戴夫

david_at_windward_dot_net
http://www.windwardreports.com

解决方案

" David Thielen" <第***** @ nospam.nospam>在留言中写道

news:33 ********************************** @ microsof t.com ...

在我的代码背后,我验证了一切。


你真的*需要验证服务器端吗?例如。你在数据库中验证控件的

内容吗??

然后我将一个标志设置为会话变量。
然后我重新加载它我所在的页面(我是重定向到页面还是另一种方式?)。
当页面加载时,我查找会话变量并找到它,我创建了一个onload脚本。


???为什么此时需要重新加载页面?假设你*做*

实际上必须验证服务器端,如果验证通过,为什么不简单地

注册客户端脚本块...?

onload脚本向另一个url启动第二个窗口。 (有没有最好的方法来执行此操作并指定网址,以便弹出窗口阻止程序不会阻止它?)


如果这是一个公共站点,不要使用showModalDialog,因为这对所有浏览器/版本都不起作用

。改为使用window.open。

我有一个名为launch的javascript变量我启动后设置为true
所以
重新加载我不会重新启动。



我认为你可能会使这个过程过于复杂......


嗨大卫,


感谢您的帖子。


在ASP.NET页面的生命周期中,一些相关的事件顺序是:

1)加载

2)验证

3)回发事件处理


您可以参考以下文章了解更多信息:


#ASP.NET页面生命周期概述
http://msdn2.microsoft.com/en-us/library/ms178472.aspx


所以我想你可以简单地检查控件事件中的IsValid属性

导致回发,例如:


protected void Button1_Click(object sender,Even如果(IsValid)

{

ClientScript.RegisterStartupScript(GetType(),& ; open2",

" javascript :window.open(''default2.aspx'')",true);

}

}


希望这会有所帮助。如果有任何不清楚的地方,请随时发布。


问候,

Walter Wang

Microsoft在线社区支持

========================================= =========

在回复帖子时,请回复群组通过你的新闻阅读器

其他人可以从你的问题中学习并从中受益。

==================== ==============================

此帖子提供按现状 ;没有保证,也没有赋予任何权利。


好的,会尝试这个。


谢谢 - 戴夫


ps - 是的,不幸的是它需要点击数据库进行验证。


-

谢谢 - 戴夫

david_at_windward_dot_net
http://www.windwardreports.com


" Walter Wang [MSFT]"写道:

嗨大卫,

感谢您的发布。

在ASP.NET页面的生命周期中,一些相关的事件顺序是:
1)加载
2)验证
3)回发事件处理

您可以参考以下文章获取更多信息:

#ASP.NET页面生命周期概述
http://msdn2.microsoft.com/en-us/library/ms178472.aspx

所以我认为您只需检查控件事件中的IsValid属性<导致回发的原因,例如:

protected void Button1_Click(object sender,EventArgs e)
{
if(IsValid)
{
ClientScript.RegisterStartupScript(GetType()," open2",
" javascript :window.open(''default2.aspx'')",true);
}
}
希望这会有所帮助。如果有什么不清楚的话,请随时在这里发帖。

问候,
Walter Wang
微软在线社区支持

======= ===========================================
回复时帖子,请回复群组通过您的新闻阅读器,以便其他人可以从您的问题中学习并从中受益。
============================ ======================

此帖子是原样提供的。没有保证,也没有授予任何权利。



Hi;

In a page, when the user clicks on a button, I want to validate all the
controls (in the code behind) and then if they are good, leave that page
alone and launch a new window with a new url also.

This is what I think is the best approach - please let me know if there is a
better one:

In my code behind I validate everything.
I then set a flag as a session variable.
I then have it reload the page I am in (do I redirect to the page or is
there another way?).
When the page loads, I look for the session variable and finding it, I
create an onload script.
The onload script launches a 2nd window to the other url. (Is there a best
way to do this and to specify the url so pop-up blockers don''t block it?)
I have a javascript variable named launched I set to true after launching so
on a reload I don''t launch again.

???

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

解决方案

"David Thielen" <th*****@nospam.nospam> wrote in message
news:33**********************************@microsof t.com...

In my code behind I validate everything.
Do you *actually* need to validate server-side? E.g. are you validating the
contents of the controls against a database...?
I then set a flag as a session variable.
I then have it reload the page I am in (do I redirect to the page or is
there another way?).
When the page loads, I look for the session variable and finding it, I
create an onload script.
??? Why do you need to reload the page at this point? Assuming you *do*
actually have to validate server-side, if validation passes why not simply
register a client script block...?
The onload script launches a 2nd window to the other url. (Is there a best
way to do this and to specify the url so pop-up blockers don''t block it?)
If this is a public site, don''t use showModalDialog as this doesn''t work
with all browsers / versions. Use window.open instead.
I have a javascript variable named launched I set to true after launching
so
on a reload I don''t launch again.



I think you may be over-complicating the process a bit...


Hi David,

Thank you for your post.

In an ASP.NET Page''s life cycle, some related events order is:
1) Load
2) Validation
3) Postback event handling

You can refer to following article for more info:

#ASP.NET Page Life Cycle Overview
http://msdn2.microsoft.com/en-us/library/ms178472.aspx

So I think you can simply check the IsValid property in the control event
which caused the postback, for example:

protected void Button1_Click(object sender, EventArgs e)
{
if (IsValid)
{
ClientScript.RegisterStartupScript(GetType(), "open2",
"javascript:window.open(''default2.aspx'')", true);
}
}

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Ok, will try this.

thanks - dave

ps - Yes unfortunately it needs to hit the DB for the validation.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

"Walter Wang [MSFT]" wrote:

Hi David,

Thank you for your post.

In an ASP.NET Page''s life cycle, some related events order is:
1) Load
2) Validation
3) Postback event handling

You can refer to following article for more info:

#ASP.NET Page Life Cycle Overview
http://msdn2.microsoft.com/en-us/library/ms178472.aspx

So I think you can simply check the IsValid property in the control event
which caused the postback, for example:

protected void Button1_Click(object sender, EventArgs e)
{
if (IsValid)
{
ClientScript.RegisterStartupScript(GetType(), "open2",
"javascript:window.open(''default2.aspx'')", true);
}
}

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



这篇关于验证字段,然后启动新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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