我,我读了我... [英] me me read me plz ...

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

问题描述

大家好,


我有一个javascript代码,我在我的btnFinish()button_click事件中使用

page.RegisterClientScriptBlock()进行注册。 />

我注意到在启动javascript

代码之前,调试器将通过整个事件运行

我的按钮。如果javascript警告

= true,我想在事件中加入一些c#代码,以及进行一些处理。例如

如果我发出警告javascript代码....


private void btnFinish(system .....,event e ....) {


string NoAccess =" < script language =''javascript''>

bool a =(警告("点击确定完成,取消返回&);)

if(a = true)然后

document.getElementById(" NoAccessAllowed")。click();

else

返回false;

< / script> "

Page.RegisterClientScriptBlock(" NoAccess",NoAccess)

string strSQL =" insert into db_Student(x,y)values(x ,y)

等等......

}


HTML codebehind:

< a href =" default.aspx" ID = QUOT; NoAccessAllowed" target =" _parent"

type =" hidden">< / a>


问:此C#代码是否会插入到db表中只有警报a =真?或者
每次触发此事件时它会这样做吗?


TIA。欢呼。

Hi ALL,

I have a javascript code which i register using
page.RegisterClientScriptBlock() in my btnFinish() button_click event.

I noticed that the debugger will run thru the whole event
for my button, before launching the javascript
code. I would like to put some c# code in the event if the javascript alert
= true, as well to do some processing. e.g.
If I put an alert javascript code ....

private void btnFinish(system....., event e ....) {

string NoAccess = " <script language=''javascript''>
bool a = (alert( " Click OK to Finish, Cancel to return"))
if (a = true) then
document.getElementById("NoAccessAllowed").click() ;
else
return false;
</script> "
Page.RegisterClientScriptBlock("NoAccess ", NoAccess )

string strSQL = "insert into db_Student (x, y) values (x, y)"
blah blah...
}

HTML codebehind:
<a href="default.aspx" id="NoAccessAllowed" target="_parent"
type="hidden"></a>

Q: Will this C# code insert into the db table only if alert a = true ? or
will it do that everytime this event is triggered ?

TIA. cheers.

推荐答案

安德鲁,


你正在尝试使用javascript错误的方式(至少在你给出的

例子中)。 Javascript只在客户端启动(并且可以使用)

机器。服务器上的代码永远不会知道客户端上发生了什么

(除非你是javascript写入隐藏字段或cookie,然后可以通过以下方式检索
服务器)。


但是你要做的事情要比那更容易。只需在首次生成页面时将

javascript警报直接附加到按钮上。

将以下代码放入页面加载中,看看会发生什么。


MyButton.Attributes.Add(" onclick"," javascript :alert(''点击确定完成,

取消返回' ');")


现在,它看起来好像你也试图在这里做其他事情。但是我不知道你打算在点击NoAccessAllowed

控制上做什么。如果您试图返回同一页面则没有必要。上面的

脚本就是这样做的。如果你试图去另一个页面,那么,如果

NoAccessAllowed正在回复帖子,那就是打败了你上面的

javascript的目的。让我知道NoAccessAllowed应该做什么和

我会看看我是否可以帮助你。


-

此致,


S. Justin Gengo,MCP

网站开发人员/程序员

www.aboutfortunate.com


混乱无序。

Nietzsche

" Andrew" <安**** @ discussions.microsoft.com>在消息中写道

新闻:DC ********************************** @ microsof t.com ...
Andrew,

You''re attempting to use javascript the wrong way here (at least in the
example you''ve given). Javascript only fires (and can be used) on the client
machine. The code on your server will never know what happens on the client
(unless you''re javascript writes to a hidden field or a cookie that can then
be retrieved by the server).

But what you''re trying to do is much easier than that. Just attach your
javascript alert directly to the button when the page is first generated.
Put the following code into your page load and see what happens.

MyButton.Attributes.Add("onclick", "javascript: alert( ''Click OK to Finish,
Cancel to return'');")

Now, it looks as if you are trying to do something else here also. But I
don''t know what you intend to do on the Click of the "NoAccessAllowed"
control. If you''re trying to return to the same page there is no need. The
script above does that. If you''re trying to go to a different page, well, if
NoAccessAllowed is doing a post back it is defeating your purpose of the
javascript above. Let me know what NoAccessAllowed is supposed to do and
I''ll see if I can help you out.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew" <An****@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.com...
大家好,

我有一个javascript代码,我在我的btnFinish()button_click事件中使用
页面注册.RegisterClientScriptBlock() 。

我注意到调试器将在启动javascript
代码之前通过整个事件运行
我的按钮。如果javascript
alert
= true,我想在事件中加入一些c#代码,以及进行一些处理。例如
如果我发出警告javascript代码....

private void btnFinish(system .....,event e ....){
string NoAccess =" < script language =''javascript''>
bool a =(警告("点击OK完成,取消返回&);)
如果(a = true)那么
document.getElementById(" NoAccessAllowed")。click();
else
return false;
< / script>
Page.RegisterClientScriptBlock(NoAccess,NoAccess)

字符串strSQL ="插入db_Student(x,y)值(x,y)"
等等......

HTML codebehind:
< a href =" default.aspx" ID = QUOT; NoAccessAllowed" target =" _parent"
type =" hidden">< / a>
问:只有当警报a = true时,此C#代码是否会插入到db表中?或者每当这个事件被触发时它会这样做吗?

TIA。欢呼。
Hi ALL,

I have a javascript code which i register using
page.RegisterClientScriptBlock() in my btnFinish() button_click event.

I noticed that the debugger will run thru the whole event
for my button, before launching the javascript
code. I would like to put some c# code in the event if the javascript
alert
= true, as well to do some processing. e.g.
If I put an alert javascript code ....

private void btnFinish(system....., event e ....) {

string NoAccess = " <script language=''javascript''>
bool a = (alert( " Click OK to Finish, Cancel to return"))
if (a = true) then
document.getElementById("NoAccessAllowed").click() ;
else
return false;
</script> "
Page.RegisterClientScriptBlock("NoAccess ", NoAccess )

string strSQL = "insert into db_Student (x, y) values (x, y)"
blah blah...
}

HTML codebehind:
<a href="default.aspx" id="NoAccessAllowed" target="_parent"
type="hidden"></a>

Q: Will this C# code insert into the db table only if alert a = true ? or
will it do that everytime this event is triggered ?

TIA. cheers.



安德鲁:

您需要了解网络编程的本质。你不能在服务器端和客户端之间转换

。当请求页面时,首先激活
服务器端代码,并将HTML呈现给浏览器。然后将触发您拥有的任何

客户端代码。直到新请求

(例如点击按钮并触发回发)才会重新启动整个

流程。单击该按钮时,页面将被回发

(基本上是重新请求的)并且事件处理程序将触发。此时你是
在服务器端,你不能在一些客户端代码触发时中断。


你可以让你的按钮输出javascript,然后有另一个按钮

重新发布处理SQL插入...但是这是3个请求(初始,

确认,保存)这是(a )慢和(b)用户统一。


通常,你将javascript附加到初始响应。所以,在页面

load中,执行:


btnFinish.Attributes.Add(" onClick"," Check();"); <你的HTML中的


< script language =" JavaScript">

function Check()

{

if(确认(Ok?))

{

返回true;

}

_doPostBack(''btnNoAccess'','''');

}

无论如何上面的代码只是虚拟代码,不是必要的工作,但是

希望能给你一些想法...


Karl

- -

我的ASP.Net教程
http:// www .openmymind.net /
http:// openmymind .net / redirector.aspx?documentId = 51 - 了解AJAX!


" Andrew" <安**** @ discussions.microsoft.com>在消息中写道

新闻:DC ********************************** @ microsof t.com ...
Andrew:
You need to understand the nature of web programming. You can''t go between
server-side and client-side as you please. When a page is requested, first
server-side code fires, and the HTML is rendered to the browser. Any
client-side code you have will then be triggered. Not until a new request
is made (such as a button being clicked and firing postback) will the entire
process restart. When the button is clicked, the page is posted back
(essentially re-requested) and the event handler fires. At this point you
are in server-side, you can''t break while some client-side code fires.

You could make your button output the javascript, then have another button
repost to handle the SQL insert...but that''s 3 requests (initial,
confirmation, save) which is (a) slow and (b) unituiative for users.

Normally, you attach the javascript to the initial response. So, in page
load, do:

btnFinish.Attributes.Add("onClick", "Check();");

in your html do:
<script language="JavaScript">
function Check()
{
if (confirm("Ok?"))
{
return true;
}
_doPostBack(''btnNoAccess'','''' );
}
Anyways the above code is just dummy code, won''t necessary work, but will
hopefully give you some ideas...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Andrew" <An****@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.com...
大家好,

我有一个javascript代码,我在我的btnFinish()button_click事件中使用
页面注册.RegisterClientScriptBlock() 。

我注意到调试器将在启动javascript
代码之前通过整个事件运行
我的按钮。如果javascript
alert
= true,我想在事件中加入一些c#代码,以及进行一些处理。例如
如果我发出警告javascript代码....

private void btnFinish(system .....,event e ....){
string NoAccess =" < script language =''javascript''>
bool a =(警告("点击OK完成,取消返回&);)
如果(a = true)那么
document.getElementById(" NoAccessAllowed")。click();
else
return false;
< / script>
Page.RegisterClientScriptBlock(NoAccess,NoAccess)

字符串strSQL ="插入db_Student(x,y)值(x,y)"
等等......

HTML codebehind:
< a href =" default.aspx" ID = QUOT; NoAccessAllowed" target =" _parent"
type =" hidden">< / a>
问:只有当警报a = true时,此C#代码是否会插入到db表中?或者每当这个事件被触发时它会这样做吗?

TIA。欢呼。
Hi ALL,

I have a javascript code which i register using
page.RegisterClientScriptBlock() in my btnFinish() button_click event.

I noticed that the debugger will run thru the whole event
for my button, before launching the javascript
code. I would like to put some c# code in the event if the javascript
alert
= true, as well to do some processing. e.g.
If I put an alert javascript code ....

private void btnFinish(system....., event e ....) {

string NoAccess = " <script language=''javascript''>
bool a = (alert( " Click OK to Finish, Cancel to return"))
if (a = true) then
document.getElementById("NoAccessAllowed").click() ;
else
return false;
</script> "
Page.RegisterClientScriptBlock("NoAccess ", NoAccess )

string strSQL = "insert into db_Student (x, y) values (x, y)"
blah blah...
}

HTML codebehind:
<a href="default.aspx" id="NoAccessAllowed" target="_parent"
type="hidden"></a>

Q: Will this C# code insert into the db table only if alert a = true ? or
will it do that everytime this event is triggered ?

TIA. cheers.






感谢您的回复。

我有完成了javascript代码并且工作正常。

我得到了警报。例如警告(确定结束测试,取消返回);

我想做的是当用户点击弹出窗口的确定按钮时

警报,我将更新数据库中的记录。


但是看起来我不能那样做服务器端代码和

客户端 - 边码不相互关联。您如何建议我实施

此更新?


我是否足够清楚? TIA。

干杯。


" Karl Seguin"写道:
Hi,

Thanks for your reply.
I have done the javascript code and it works fine.
I got the alert working. e.g. alert("OK to end the test, Cancel to return");
What I wanted to do was that when the user clicks the OK button of the popup
alert, I will update a record in the database.

However it looks like I can''t do that coz the server-side code and
client-side code doesn''t relate to each other. How do you suggest I implement
this update ?

Am I being clear enough ? TIA.
Cheers.

"Karl Seguin" wrote:
安德鲁:
您需要了解网络编程的本质。您不能随意在服务器端和客户端之间切换。当请求页面时,首先激活服务器端代码,并将HTML呈现给浏览器。然后将触发您拥有的任何客户端代码。直到发出新请求(例如点击按钮并触发回发),整个
进程才会重新启动。单击该按钮时,页面将被回发
(基本上是重新请求的)并且事件处理程序将触发。此时你处于服务器端,当一些客户端代码触发时你不能断开。

你可以让你的按钮输出javascript,然后有另一个按钮<重新发布以处理SQL插入...但是这是3个请求(初始,
确认,保存),这是(a)缓慢和(b)用户的单一性。

通常,您将javascript附加到初始响应。所以,在页面
加载中,执行:

btnFinish.Attributes.Add(" onClick"," Check();");

in你的html做:
< script language =" JavaScript">
功能检查()
{
if(确认(确定?))
{
返回true;
}
_doPostBack(''btnNoAccess'','''');
}

无论如何以上代码只是虚拟代码,不是必要的工作,但希望能给你一些想法......

Karl
-
我的ASP.Net教程
http://www.openmymind.net/
< a rel =nofollowhref =http://openmymind.net/redirector.aspx?documentId=51target =_ blank> http://openmymind.net/redirector.aspx?documentId=51 - 了解AJAX!

安德鲁 <安**** @ discussions.microsoft.com>在消息中写道
新闻:DC ********************************** @ microsof t.com。 ..
Andrew:
You need to understand the nature of web programming. You can''t go between
server-side and client-side as you please. When a page is requested, first
server-side code fires, and the HTML is rendered to the browser. Any
client-side code you have will then be triggered. Not until a new request
is made (such as a button being clicked and firing postback) will the entire
process restart. When the button is clicked, the page is posted back
(essentially re-requested) and the event handler fires. At this point you
are in server-side, you can''t break while some client-side code fires.

You could make your button output the javascript, then have another button
repost to handle the SQL insert...but that''s 3 requests (initial,
confirmation, save) which is (a) slow and (b) unituiative for users.

Normally, you attach the javascript to the initial response. So, in page
load, do:

btnFinish.Attributes.Add("onClick", "Check();");

in your html do:
<script language="JavaScript">
function Check()
{
if (confirm("Ok?"))
{
return true;
}
_doPostBack(''btnNoAccess'','''' );
}
Anyways the above code is just dummy code, won''t necessary work, but will
hopefully give you some ideas...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Andrew" <An****@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.com...
大家好,

我有一个javascript代码,我在我的btnFinish()button_click事件中使用
page.RegisterClientScriptBlock()注册。

我注意到调试器将在启动javascript
代码之前通过整个事件运行
我的按钮。如果javascript
alert
= true,我想在事件中加入一些c#代码,以及进行一些处理。例如
如果我发出警告javascript代码....

private void btnFinish(system .....,event e ....){
string NoAccess =" < script language =''javascript''>
bool a =(警告("点击OK完成,取消返回&);)
如果(a = true)那么
document.getElementById(" NoAccessAllowed")。click();
else
return false;
< / script>
Page.RegisterClientScriptBlock(NoAccess,NoAccess)

字符串strSQL ="插入db_Student(x,y)值(x,y)"
等等......

HTML codebehind:
< a href =" default.aspx" ID = QUOT; NoAccessAllowed" target =" _parent"
type =" hidden">< / a>
问:只有当警报a = true时,此C#代码是否会插入到db表中?或者每当这个事件被触发时它会这样做吗?

TIA。欢呼。
Hi ALL,

I have a javascript code which i register using
page.RegisterClientScriptBlock() in my btnFinish() button_click event.

I noticed that the debugger will run thru the whole event
for my button, before launching the javascript
code. I would like to put some c# code in the event if the javascript
alert
= true, as well to do some processing. e.g.
If I put an alert javascript code ....

private void btnFinish(system....., event e ....) {

string NoAccess = " <script language=''javascript''>
bool a = (alert( " Click OK to Finish, Cancel to return"))
if (a = true) then
document.getElementById("NoAccessAllowed").click() ;
else
return false;
</script> "
Page.RegisterClientScriptBlock("NoAccess ", NoAccess )

string strSQL = "insert into db_Student (x, y) values (x, y)"
blah blah...
}

HTML codebehind:
<a href="default.aspx" id="NoAccessAllowed" target="_parent"
type="hidden"></a>

Q: Will this C# code insert into the db table only if alert a = true ? or
will it do that everytime this event is triggered ?

TIA. cheers.




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

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