【问题标题】:Pass parameters with a asp:Button onClick with x-jquery-tmpl使用 asp 传递参数:Button onClick with x-jquery-tmpl
【发布时间】:2013-11-24 20:55:43
【问题描述】:

我正在使用带有 x-jquery-tmpl 的 asp.net c#

所以我试图将数据传递给后面的代码。我正在根据一些数据生成一系列 div,并使用模板分配 div 的名称/值。

我遇到的问题是,当信息被传递时,它以 jquery 形式显示,而不是显示实际值。

     <script id="SomeTemplate" type="text/x-jquery-tmpl">
        <div class="grid_12">
        <div class="box">
        <div class="header">
        <img alt="img" width="16" height="16" />
                    <h3>Title: ${text}</h3>
                    <div class="box" style="float:right; margin-top: -4px; margin-right: 8px" >
                        <asp:Button id="btn${text}" Text="${text}" runat="server" OnClick="RedirectPage" CommandArgument=${text} style="vertical-align:middle"/>
                    </div>
                </div>
                <div class="content">
                    <canvas id="cvs${text}" width="1600" height="750" style="border: 1px solid #222;">[No canvas support]</canvas>
                </div>
            </div>
    </div>
</script>

当按钮被点击时,后面的代码被执行:

protected void RedirectPage(object sender, EventArgs e)
    {
        Button test = (Button)sender;
        string t = test.CommandArgument.ToString(); // returns $(text)
        Response.Redirect("http://www.address.com/" + t);
    }

问题是我想使用作为重定向的一部分传递的值。

任何帮助将不胜感激。

谢谢

【问题讨论】:

标签: c# javascript jquery asp.net jquery-templates


【解决方案1】:

我已经换掉了:

<asp:Button id="btn${text}" Text="${text}" runat="server" OnClick="RedirectPage" CommandArgument=${text} style="vertical-align:middle"/>

为:

<input type="button" id="btnSave" onclick="javascript:redirectPage('${text}')" value="click me"/>

然后我可以使用 __doPostBack 并在页面加载端处理这个问题。更多详情请见How to use dopostback

感谢@jbl 为我指明了正确的方向

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    • 2013-02-27
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 2014-10-07
    相关资源
    最近更新 更多