简单对话框问题

liyingjie5360 2010-11-06 08:47:09
public void Confirm(string message)
{
StringBuilder js = new StringBuilder();
js.Append(string.Format("if(!confirm('{0}'))", message));
Page.ClientScript.RegisterStartupScript(this.GetType(), "error", js.ToString(), true);
}


此方法可以弹出确认对话框,分别是“确认”、“取消”两个按钮,我要选择“确认”,这个代码要怎么写?请给出例子
...全文
195 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
hch126163 2010-11-06
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 karascanvas 的回复:]

执行服务器端的代码,你得先postback

<asp:LinkButton OnClick="DoSomething" OnClientClick="return confirm('message')"
[/Quote]

这个方法可以,

当然还可以用ajax!
种草德鲁伊 2010-11-06
  • 打赏
  • 举报
回复
执行服务器端的代码,你得先postback

<asp:LinkButton OnClick="DoSomething" OnClientClick="return confirm('message')"
SK_Aqi 2010-11-06
  • 打赏
  • 举报
回复
liyingjie5360 2010-11-06
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 karascanvas 的回复:]
是不是这个意思?


JScript code


if(confirm('message')){
// 点确认时执行
}
else{
// 点取消时执行
}
[/Quote]

意思是这个意思,但是我是在后台写的,要执行后台的一个方法。不知道要怎么写
种草德鲁伊 2010-11-06
  • 打赏
  • 举报
回复
是不是这个意思?



if(confirm('message')){
// 点确认时执行
}
else{
// 点取消时执行
}


liyingjie5360 2010-11-06
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 sk_aqi 的回复:]
怎么会不行呢?
记得好像得返回值才可以?
public string test()
{
GlobalGovermentSystem.BLL.File_share bll=new GlobalGovermentSystem.BLL.File_share();
bll.Update2(model);
return "";
}
[/Quote]


那返回的就是空啊。。没得值的。真的不行。我试了的。
SK_Aqi 2010-11-06
  • 打赏
  • 举报
回复
怎么会不行呢?
记得好像得返回值才可以?
public string test()
{
GlobalGovermentSystem.BLL.File_share bll=new GlobalGovermentSystem.BLL.File_share();
bll.Update2(model);
return "";
}
liyingjie5360 2010-11-06
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 sk_aqi 的回复:]
你这里明显的是执行的后台的代码啊
这样写: confirmFun 就是一个方法名: 例如:"test()";
test方法就是写:

C# code
public test()
{
GlobalGovermentSystem.BLL.File_share bll=new GlobalGovermentSystem.BLL.File_share();
bll.Upda……
[/Quote]


不行的。。。不执行方法。。。虽说是后台写代码但是实质是要写js代码。
SK_Aqi 2010-11-06
  • 打赏
  • 举报
回复
public void test()
{

}
SK_Aqi 2010-11-06
  • 打赏
  • 举报
回复
你这里明显的是执行的后台的代码啊
这样写: confirmFun 就是一个方法名: 例如:"test()";
test方法就是写:
public test()
{
GlobalGovermentSystem.BLL.File_share bll=new GlobalGovermentSystem.BLL.File_share();
bll.Update2(model);
}
liyingjie5360 2010-11-06
  • 打赏
  • 举报
回复
public void Confirm(string message,string confirmFun,string cancelFun)
{
StringBuilder js = new StringBuilder();
js.Append(string.Format("if(confirm('{0}'))", message));
js.Append("{"+confirmFun+"}");
if(cancelFun!=null && cancelFun!=""){js.Append("else{"+cancelFun+"}");}
Page.ClientScript.RegisterStartupScript(this.GetType(), "error", js.ToString(), true);
}


调用方法: string msg="存在相同文件名,是否覆盖原来的文件?";
Confirm(msg, "GlobalGovermentSystem.BLL.File_share bll=new GlobalGovermentSystem.BLL.File_share(); bll.Update2(model)", "");

其中的方法调用无效,请问这个到底要怎么写啊?急。。。。
SK_Aqi 2010-11-06
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 liyingjie5360 的回复:]
引用 1 楼 hch126163 的回复:
public void Confirm(string message,string confirmFun,string cancelFun)
{
StringBuilder js = new StringBuilder();
js.Append(string.Format("if(confirm('{0}'))", message));
js.……
[/Quote]
总之你调一下,看怎么凑成你想要的脚本就行了.
Ny-6000 2010-11-06
  • 打赏
  • 举报
回复
有确认取消的,建议直接 写页面中,就不要写后台了.
liyingjie5360 2010-11-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hch126163 的回复:]
public void Confirm(string message,string confirmFun,string cancelFun)
{
StringBuilder js = new StringBuilder();
js.Append(string.Format("if(confirm('{0}'))", message));
js.Append("{"+conf……
[/Quote]

请问这位大虾,confirmFun我传的是方法,但这是string 类型的,传方法不能执行吧??你的方法是可行的,但是。。。
SK_Aqi 2010-11-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhouzangood 的回复:]
mark
[/Quote]
希望你的别被删,1楼的应该就可以
liyingjie5360 2010-11-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 chen_ya_ping 的回复:]
引用楼主 liyingjie5360 的回复:
public void Confirm(string message)
{
StringBuilder js = new StringBuilder();
js.Append(string.Format("if(!confirm('{0}'))", message));
Page.ClientScript.RegisterStar……

……
[/Quote]

不是的。这个有确认与取消两个按钮。。。
chen_ya_ping 2010-11-06
  • 打赏
  • 举报
回复
[Quote=引用楼主 liyingjie5360 的回复:]
public void Confirm(string message)
{
StringBuilder js = new StringBuilder();
js.Append(string.Format("if(!confirm('{0}'))", message));
Page.ClientScript.RegisterStar……
[/Quote]
反正都是选择确认,为什么还要选择呢?
hch126163 2010-11-06
  • 打赏
  • 举报
回复
public void Confirm(string message,string confirmFun,string cancelFun)
{
StringBuilder js = new StringBuilder();
js.Append(string.Format("if(confirm('{0}'))", message));
js.Append("{"+confirmFun+"}"};
if(cancelFun!=null && cancelFun!=""){js.Append("else{"+cancelFun+"}"};}
Page.ClientScript.RegisterStartupScript(this.GetType(), "error", js.ToString(), true);
}

62,271

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧