1

基本上我有一个带有 runat 服务器标签的表单。在这个表单中,我有一个 asp 转发器和一个提交按钮——但我也想有一个按钮,它会在我的代码中调用 ac# 方法——有人可以给我一个关于如何去做的想法吗?同样在此代码中,即使它的自动回发值为 true,也不会触发 selectindexchanged 事件,这很奇怪:/

谢谢

编辑 OK 解决方案似乎是删除操作选项卡,然后我通过一些 JavaScript 设置属性:) 为什么事情不能简单明了


    <form action="broadcast.aspx" id="bcForm" runat="server" onsubmit="chkChecks()"> 
            <a class="btn btn-warning" href="#" title="Create new product"> <i class="icon-plus icon-white"></i> Create new product</a> &nbsp &nbsp <a id="bcItems" data-toggle="modal" class="btn btn-primary" title="Broadcast" onclick="chkItems()"><i class="icon-share icon-white"></i> Broadcast</a>

</br></br>
<p>Filters:
<asp:DropDownList ID="groupFilter" runat="server" ToolTip="Groups"        AutoPostBack="True" onselectedindexchanged="groupFilter_SelectedIndexChanged1" ></asp:DropDownList></p>


   <div>
        <asp:Repeater ID="DepartmentList" runat="server"  OnItemmDataBound="DepartmentsList_ItemDataBound">
   <HeaderTemplate>
         <table id="grouptable" class="table table-bordered table-striped sortable"> 
                    <thead>
                            <tr>
                            <th class="sorttable_nosort" >Broadcast 
                                <br> </br><a class="label label-inverse" onclick="checkAll()">Check All</a>&nbsp<a class="label label-inverse" onclick="uncheckAll()">Uncheck All</a></th>
                            <th class="sorttable_numeric">ID</th>
                            <th>Name</th>
                            <th>Last Modified</th>
                            <th>Actions</th>
                        </tr>
                        </thead>
                        <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                            <tr>
                            <td WIDTH="100">
                            <input type="checkbox" name="BroadcastSelect[]" value="<%# Eval("DEPT_ID") %>"</input></td>
                            <td>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("DEPT_ID") %>'></asp:Label></td>
                            <td><%# Eval("DESC") %></td>
                            <td>
                                <asp:Label ID="Label2" runat="server" Text='<%# Eval("CHG_DATE") %>'></asp:Label></td>
                            <td><a class="btn btn-info" href="<%# Eval("gURL") %>">Edit</a>&nbsp;&nbsp<asp:HyperLink ID="HyperLink1" runat="server" CssClass="btn btn-danger">Broadcast Now</asp:HyperLink></td>
                            </tr>
                </ItemTemplate>
                <FooterTemplate>
                            </tbody>
                    </table>
                </FooterTemplate>
                </asp:Repeater>
                </div>



              <div id="myModal" class="modal hide fade" runat="server">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal">&times; Select A Branch</h3>
                </div>
                <div class="modal-body">
                  <h4>Test</h4>

                <asp:Repeater ID="cfgList" runat="server">
                    <HeaderTemplate>
                   <table id="configtable" class="table table-bordered table-striped"> 
                    <thead>
                            <tr>
                            <th>Broadcast</th>
                            <th>Branch No.</th>
                            <th>Branch Name</th>
                        </tr>
                        </thead>
                        <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                            <tr>
                            <td>
                            <input type="checkbox" name="BranchSelection[]" value="<%# Eval("branch") %>"</input></td>
                            <td><%# Eval("branch") %></td>
                            <td><%# Eval("name") %></a> </td>
                            </tr>
                </ItemTemplate>
                <FooterTemplate>
                            </tbody>
                    </table>
                </FooterTemplate>
                </asp:Repeater>


                </div>

                <div class="modal-footer">
                  <!--<a class="btn btn-success" onclick="document.getElementById('bcForm').submit()" title="Broadcast"><i class="icon-share icon-white"></i> Broadcast</a> -->
                  <a class="btn btn-success" onclick="chkBranches()" title="Broadcast"><i class="icon-share icon-white"></i> Broadcast</a>
                  <!--<input type="submit" value="Broadcast3" class="btn btn-success"/> -->
                  <div id="myDiv"></div>
                </div>
              </div>
              <!-- <a data-toggle="modal" href="#myModal" class="btn btn-primary">Broadcast Testing</a> -->
                <!--<a class="btn btn-success" onclick="document.getElementById('bcForm').submit()" title="Broadcast"><i class="icon-share icon-white"></i> Broadcast</a>-->
                <a id="bcItems2" data-toggle="modal" class="btn btn-primary" title="Broadcast" onclick="chkItems()"><i class="icon-share icon-white"></i> Broadcast</a>
                <ul class="pager">
                <li>
                <asp:Button ID="previousBtn" runat="server" Text="Prev" cssclass="search-query" 
                        Width="80px"/>
                </li>
                <li>
                <asp:Button ID="nextBtn" runat="server" Text="Next" cssclass="search-query" 
                        Width="80px"/>
                </li>
                </ul>
                </form>
4

4 回答 4

5

我一定在你的问题中遗漏了一些东西,因为这并不难,但是你去......

HTML:

<asp:Button runat="server" Text="Whatever" OnClick="SomeMethod_Click"/>

后面的 C# 代码

public void SomeMethod_Click(object sender, EventArgs e);
于 2012-08-16T16:03:37.603 回答
0

首先从表单中删除 action 属性。– 点网梦想家

这基本上是答案,检查我用修复更新的原始帖子:)

DotNet Dreamer 的道具

于 2012-08-21T14:55:42.763 回答
-1

例子:

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl1.Text="Your name is " & txt1.Text
End Sub
</script>

<html>
<body>

<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

帮助链接:http ://www.w3schools.com/aspnet/aspnet_button.asp

于 2012-08-16T16:06:34.390 回答
-3

在下拉列表属性中,您可以设置 AutoPostBack = true。这样,它会将帖子发送回服务器,因此可以触发事件。

哦。对不起,我没看到你已经有了

于 2012-08-16T16:06:16.930 回答