从code jQuery的触发事件背后文件(asp.net) [英] trigger jQuery event from code behind file (asp.net)

查看:144
本文介绍了从code jQuery的触发事件背后文件(asp.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在一个简单的应用程序,显示来自DB联系人列表。这是可能的新的联系人添加到数据库,如果一个新的联系人成功添加一条消息,告诉如此可见。

这个地方显示在其默认设置为可见=虚假的div内的标签。当联系人添加成功可见被设置为true,一个消息在标签文本中。到目前为止好。

问题是我想要的消息消失10秒后,而这样做,我想使用jQuery。我所需要的帮助是如何触发隐藏文件code jQuery函数。我试图检查元素存在,如果是火的功能,但没有任何反应。

在此先感谢!

从code背后:

 保护无效ContactObjectDataSource_Inserted(对象发件人,ObjectDataSourceStatusEventArgs E){
        如果(e.Exception!= NULL){
            AddErrorMessage(发生错误。);
            e.ExceptionHandled = TRUE;
        }
        其他{
            successMessage.Visible =真;
            message.Text =接触已成功添加!
        }
    }

从Default.aspx的:

 < D​​IV ID =successMessage=服务器可见=假>
            < ASP:标签ID =消息=服务器>< / ASP:标签>
    < / DIV>

从JS文件:

  VAR胶囊= {    hideMessage:功能(){
        的setTimeout(函数(){
                $(#successMessage),隐藏(变脸,{},1000)。
        },5000);
    }
}在window.onload = Capsule.init;


解决方案

您可以使用下面的code调用从C#jquery的功能:

  ScriptManager.RegisterStartupScript(this.Page,this.GetType(),TMP,<脚本类型=文/ JavaScript的'> hideMessage();< /脚本>中,FALSE);

I'm working on an simple application which shows a list of contacts from a db. It's possible to add new contacts to the db, and if a new contact is successfully added a message telling so is visible.

The place is shown in a label inside a div which by default is set to Visible=false. When a contact is successfully added Visible is set to true and a message is shown in the labels text. So far so good.

The thing is that I want the message to disappear after 10 seconds, and for doing that I want to use jQuery. What I need help with is how to trigger the jQuery function from the code behind file. I've tried to check if the element exists and if so fire the function, but nothing happens.

Thanks in advance!

from code behind:

protected void ContactObjectDataSource_Inserted(object sender, ObjectDataSourceStatusEventArgs e) {
        if (e.Exception != null) {
            AddErrorMessage("An error occurred.");
            e.ExceptionHandled = true;
        }
        else {
            successMessage.Visible = true;
            message.Text = "The contact was successfully added!";
        }
    }

from default.aspx:

    <div id="successMessage" runat="server" visible="False">
            <asp:Label ID="message" runat="server"></asp:Label>
    </div>

from the js-file:

var Capsule = {

    hideMessage: function () {
        setTimeout(function() {
                $("#successMessage").hide("fade", {}, 1000);
        }, 5000);
    }
}

window.onload = Capsule.init;

解决方案

you can use the following code to call the jquery function from c#:

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script type='text/javascript'>hideMessage();</script>", false);

这篇关于从code jQuery的触发事件背后文件(asp.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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