【问题标题】:remain TextBox value after the page refreshed页面刷新后保留TextBox值
【发布时间】:2020-04-04 15:46:46
【问题描述】:

我有一个文本框,这就是我给它赋值的方式

var start = moment().subtract(6, 'days');
var end = moment();

        $('#datePicker').daterangepicker({
            timepicker: false,
            startDate: start,
            endDate: end,
            ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            }
        }, cb);

        cb(start,end);

        function cb(start, end) {
            $('#datePicker').html(start + ' - ' + end);
        }

我的界面

如您所见,我选择日期值(04/04/2020 - 04/04/2020)并单击按钮,它将从数据库中检索数据并刷新页面,刷新后,文本框值将变回 03/29/2020 - 04/04/2020(默认使用一周前的日期)。顺便说一句,此文本框是 Asp.net 文本框

有什么方法可以在刷新后保留文本框的值?

如果您需要更多信息,请告诉我

【问题讨论】:

    标签: javascript asp.net daterangepicker


    【解决方案1】:

    如果 cb(start,end); 这一行在回发时覆盖了您的文本框,请执行此操作。

    在 aspx 第一个页面上添加文字以将变量 isPostBack 呈现为 javascript。

    <asp:Literal runat="server" ID="txtExtraScriptVariables" EnableViewState="false" />
    

    然后在后面的代码上渲染它。

    txtExtraScriptVariables.Text 
        = string.Format("var isPostBack = {0};", IsPostBack.ToString().ToLower());
    

    现在在你的脚本中使用它

    if(!isPostBack)
        cb(start,end);
    

    【讨论】:

      猜你喜欢
      • 2011-08-23
      • 2016-12-20
      • 1970-01-01
      • 2017-03-05
      • 1970-01-01
      • 1970-01-01
      • 2018-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多