JavaScript的confirm无code code背后 [英] Javascript confirm without code in code behind

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

问题描述

我有动态添加imagebuttons一个网页,我希望他们当你点击它们(删除)发送一个确认。

I have a page with dynamically added imagebuttons, and i want them to send a confirm when you click them(for deletion).

由于他们是动态的我不能在事件。点击code什么。

Since they are dynamic i cant code anything in a .click event.

怎么样了做到这一点的最好方法是什么?检查是否真的还是假的,然后将其与对照作为参数发送到删除功能在code后面?或任何其他方式?

Hows the best way to do this? check if true or false and then send it to a delete function in code behind with the control as parameter? or any other way?

感谢

推荐答案

如果您希望能够取消提交的的OnClientClick 属性设置为字符串返回与函数名。然后,客户端脚本可以返回取消提交

If you want to be able to cancel the submission, set the OnClientClick property to the string "Return" and the function name. The client script can then cancel the submission by returning false.

检查的ImageButton <一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.imagebutton.onclientclick%28v=VS.85%29.aspx\"相对=nofollow> clientclick 属性。

check imagebutton clientclick property.

void Button1_Click(Object sender, EventArgs e)
        Label1.Text = "Server click handler called.";
    End Sub

您的动态生成的ImageButton应该有点像这样:所有imagebuttons创建commman事件哈德勒并设置 ID 这些ImageButton的主键值。

your dynamic generated imagebutton should be somewhat like this: Create commman event hadler for all imagebuttons and set the id of these imagebutton to the primary key value.

响应按钮Web服务器控件事件在客户端脚本的详情:

您可以创建自定义的ImageButton用户控件,将提供有关click事件删除功能。在ItemRowCreated或GridView控件RowCreated事件的事件哈德勒分配给这些动态添加的控制。

You can create a custom imagebutton usercontrol that will provide the delete functionality on click event. On ItemRowCreated or GridView RowCreated events assign event hadler to these dynamically added control.

如果他们没有在任何数据绑定控件然后简单的在运行时分配有属性。

If they are not in any databind control then simple assign there properties at run time.

protected void Page_Init(object sender, EventArgs e)
    {
        ImageButton btn = new ImageButton();
        btn.ID = "1";
        btn.ImageUrl = "http://icons.iconarchive.com/icons/deleket/button/256/Button-Fast-Forward-icon.png";
        btn.OnClientClick = "return confirm('Ready to submit.')";
        btn.Click += new ImageClickEventHandler(btn_Click);
        this.form1.Controls.Add(btn);
    }

检查控件的ID在事件处理程序。

check the control id in event handler.

private void btn_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton btn = (ImageButton)sender;
            Response.Write("<script>alert('Image button with id = " + btn.ID + "clicked');</script>");
        }

然后perfom删除操作。

and then perfom delete operation

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

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