在用户控件中回发后保留文本框中的值 [英] preserve value in textbox after postback in user control

查看:111
本文介绍了在用户控件中回发后保留文本框中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过jquery将文本加载到文本框中:

I am loading text into a textbox through jquery as so:

 $.ajax({
        type: "POST",
        url: "../myfile.ascx/myfunction",
        data: "{variable:'" + value + "'}",
        contentType: "application/json",
        dataType: "json",
        success: function (response) {
            $('input[id$=txtMyTextBox]').val(response.d);

        }
    });

这部分工作正常,但是当我导致页面从其他控件回发时,我松开了它在txtMyTextBox中插入的值.现在我正在使用用户控件,因此我使用了databind而不是页面加载.我试过了:

this portion works fine, but when I cause the page to postback from other controls I loose the value it had inserted in txtMyTextBox..Now I am using a user control so I have a databind instead of page load. I tried this:

protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "RefreshJob();", true);
    }

但是那也不会带回值.我添加了一个隐藏字段,该字段在任何回发后都会保存该值,但不确定如何将其保存在文本框中.

but that wouldn't bring back the value either. I added a hidden field which holds the value after any postback, but not sure what to do to keep the value in the textbox aswell.

推荐答案

我认为您正在使用html输入元素,而是使用asp文本框控件,并使用$('#<%=txtbox.ClientID%>').val(response.d);将其ID传递给jquery,并使用viewstate维护文本框的状态控制

I think you are using html input element, use asp textbox control instead and pass it's ID to jquery using $('#<%=txtbox.ClientID%>').val(response.d); and use viewstate for maintaining state of the textbox control

这篇关于在用户控件中回发后保留文本框中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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