C#Web应用程序中的消息框 [英] Message Box in C# Web Application

查看:86
本文介绍了C#Web应用程序中的消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到数据库的Web应用程序,并根据用户在Web表单上输入的2个字段填充

数据网格。

我有一个尝试捕获阻止以确保用户输入数据库中未找到的
值(日期),然后我将用户重定向到输入值的

origianl页面。


我想要一个消息框说他们输入了无效的日期(不是

检查日期格式,但是它们会记录不返回的日期
db中的任何值,n因此db错误)


到目前为止,我有这个

catch

{


Response.Write("< script> window.alert(''No Entries Found。'')< / script>");

}


我希望用户在点击此消息框后重定向到日期输入字段。我该怎么办?如果我尝试在response.write之后添加

Response.Redirect(" Main.aspx"),它会忽略消息框中的

并简单地重定向,这不是我想要的是什么。


任何输入都值得赞赏


谢谢

I have a web application whic connects to the database and populates a
datagrid based on 2 fields the user enters on the web form.
I have a try catch block to make sure that in case the user enters
values(dates) not found in database, then i redirect the user to the
origianl page where they enter the values.

I would like a message box saying they entered invalid dates(not a
check for date format, but that they entred dates which dont return
any values in the db, n hence the db error)

so far, i have this
catch
{

Response.Write("<script>window.alert(''No Entries Found.'')</script>");
}

I would like the user to be redirected to the date entry field after
clicking this messagebox.How do i do that? If i try to add
Response.Redirect("Main.aspx") after the response.write, it ignores
the message box and simply redirects, whic is not what i want.

Any inputs wud be appreciated

THanks

推荐答案

Response.Redirect在服务器上发生,而页面正在处理。

因此,如果你输入任何代码向页面写任何内容,它将

没有发生,因为当前的页面在它到达

浏览器之前被卸载了。如果你想让页面在客户端重定向(也就是说,在客户端弹出警告框后),你最简单的解决方案就是使用

JavaScript这样做(document.location = url;)。如果你需要在重定向之前在服务器上进行更多的处理,你可以使用JavaScript来发布表单并在服务器端进行重定向。


-

HTH,

Kevin Spencer

..Net开发商

微软MVP

大件物品组成

很多小东西。


ben < SK **** @ yahoo.com>在消息中写道

新闻:ba ************************** @ posting.google.c om ...
Response.Redirect occurs on the server, while the Page is processing.
Therefore, if you put in any code that writes anything to the Page, it will
not happen, as the current Page is unloaded before it ever reaches the
browser. If you want the page to redirect on the client side (that is, after
the alert box pops up on the client), your simplest solution would be to use
JavaScript to do it (document.location = url;). If you need to do more
processing on the server prior to redirecting, you could use JavaScript to
post the form and do the Redirect on the server side.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"ben" <sk****@yahoo.com> wrote in message
news:ba**************************@posting.google.c om...
我有一个连接到数据库的Web应用程序,并根据用户在Web表单上输入的2个字段填充
数据网格。
我有一个try catch块来制作确保如果用户输入数据库中未找到的值(日期),我会将用户重定向到
origianl页面,在那里输入值。

我想要一个消息框说他们输入的是无效日期(不是检查日期格式,但是他们记录的日期不会返回数据库中的任何值,因此db错误)
了。

Response.Write("< script> window.alert(''No Entries Found。'')< ; / script>");
}

我希望用户在点击此消息框后重定向到日期输入字段。我该怎么办?如果我尝试在response.write之后添加Response.Redirect(" Main.aspx"),它会忽略消息框并简单地重定向,这不是我想要的。

任何输入都值得赞赏

THanks
I have a web application whic connects to the database and populates a
datagrid based on 2 fields the user enters on the web form.
I have a try catch block to make sure that in case the user enters
values(dates) not found in database, then i redirect the user to the
origianl page where they enter the values.

I would like a message box saying they entered invalid dates(not a
check for date format, but that they entred dates which dont return
any values in the db, n hence the db error)

so far, i have this
catch
{

Response.Write("<script>window.alert(''No Entries Found.'')</script>");
}

I would like the user to be redirected to the date entry field after
clicking this messagebox.How do i do that? If i try to add
Response.Redirect("Main.aspx") after the response.write, it ignores
the message box and simply redirects, whic is not what i want.

Any inputs wud be appreciated

THanks





Kevin,
感谢您立即回复。

您可以发布soem示例代码来执行document.location代码,因为

im不熟悉这个。 />
谢谢

Ben

***通过Developersdex发送 http://www.developersdex.com ***

不要只是参加USENET ......获得奖励!

Kevin,
Thanks for ur immediate reply.
Can u plz post soem sample code for doing the document.location code, as
i m not familiar with this.
Thanks
Ben
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


ok ...找出了

window.document.location(''blahblah.aspx'')的语法......

无论如何,鼻涕做任何事都不会重定向....


任何想法?


***发送来自Developersdex http://www.developersdex.com ***

不要刚参加USENET ......获得奖励!
ok...figured out the syntax for
window.document.location(''blahblah.aspx'')...
howevre it doe snot do anything n does not redirect either....

any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


这篇关于C#Web应用程序中的消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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