【问题标题】:Website redirect inside Repeater中继器内的网站重定向
【发布时间】:2014-12-17 22:29:38
【问题描述】:

我一直在编写一个小型网站,它对数据库进行检查,然后创建一堆自定义按钮,当点击这些按钮时,它们会重定向到不同的本地 IP 地址。

到目前为止,我已经让中继器填充并显示网站上的按钮,但尽我所能,我无法让网站重定向甚至触发 on_click 事件。

这是我目前所拥有的相关内容

<script runat ="server">
    Sub Button_Click()
        TextBox1.Text = "test"
        Response.Redirect("http://www.musicsystems.com")
    End Sub
</script>
<style>
        .ams-button {
            border: 0;
            cursor: pointer;
            height: 60px;
            line-height: 60px;
            margin: .25em;
            margin-left: .5em;
            position: relative;
        }

        .ams-button-edge {
            border: 0;
            float: left;
            height: 60px;
            line-height: 60px;
            margin: 0;
            padding: 0;
            max-width: 30px;
            min-width: 30px;
            width: 30px;
        }

        .ams-button-left {
            background: url(Content/images/z1/parts/left.png) no-repeat center center;
        }

        .ams-button-middle {
            background: url(Content/images/z1/parts/middle.png) repeat-x center center;
            border: 0;
            float: left;
            height: 60px;
            line-height: 60px;
            margin: 0;
            padding: 0;
            max-width: 11em;
            min-width: 11em;
            width: 11em;
        }

        .ams-button-right {
            background: url(Content/images/z1/parts/right.png) no-repeat center center;
        }

        .ams-button-text {
            color: #fff;
            font-size: 15px;
            font-weight: bold;
            height: 50px;
            line-height: 50px;
            margin: 0 21px;
            overflow: hidden;
            text-align: center;
            vertical-align: middle;
            white-space: nowrap;
        }
    </style>

<form id="form1" runat="server" onclick="Button_Click()">
            <asp:Repeater ID="btnlist" runat="server">
                <HeaderTemplate>
                </HeaderTemplate>
                <ItemTemplate>
                    <div title="<%#Container.DataItem(1)%>" class="ams-button" >
                        <div class="ams-button-edge ams-button-left"></div>
                        <div class="ams-button-middle" >
                            <div class="ams-button-text" runat="server" ><%#Container.DataItem(0)%></div>
                        </div>
                        <div class="ams-button-edge ams-button-right"></div>
                    </div>
                </ItemTemplate>
                <FooterTemplate>
                </FooterTemplate>
            </asp:Repeater>

            <br />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </form>

任何人的帮助将不胜感激

【问题讨论】:

    标签: html asp.net vb.net webforms repeater


    【解决方案1】:

    首先,您应该确保您的语法有效。改变

    <script runat ="server">
    

    <script runat="server">
    

    然后,您应该使用 Web Forms Button 控件创建一个按钮。把它放在 ItemTemplate 中。如果需要,可以通过 CssClass 属性应用正确的 css。

    <asp:Button runat="server" OnClick="Button_Click" Text="Click me" />
    

    也改变

    Sub Button_Click()
    

    Protected Sub Button_Click(sender As Object, e As EventArgs)
    

    这将为它提供正确的签名,以便它可以找到事件处理程序。

    【讨论】:

    • 谢谢。我已更改语法以匹配。将其设置为 Web 表单按钮的问题在于,我无法设置格式以匹配将要加载的使用上述格式的站点的其余部分。
    • 如果我将其更改为 Web 表单按钮,它会起作用,但我会失去我们当前的外观。
    • @Wroof 这就是我提到CssClass attribute的原因。
    • @Wroof 你可以使用图片按钮
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    相关资源
    最近更新 更多