基本上我有一个带有runat服务器标签的表单。在这个形式我有一个asp转发器和asubmit按钮 - 但我也想有一个按钮,将在我的代码中调用一个c#方法 - 有人可以请你告诉我如何去做这个?同样在这段代码中,selectindexchanged事件即使其autopostback值为true也不会触发,这很奇怪:/
感谢
修改 好的解决方案似乎是删除动作选项卡,然后我通过一些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>     <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> <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>  <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">× 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>
答案 0 :(得分:5)
我必须在你的问题中遗漏一些东西,因为这并不困难,但是你走了......
HTML:
<asp:Button runat="server" Text="Whatever" OnClick="SomeMethod_Click"/>
背后的C#代码
public void SomeMethod_Click(object sender, EventArgs e);
答案 1 :(得分:0)
首先从表单中删除action属性。 - DotNet Dreamer
这基本上就是答案,查看我用修复程序更新的原始帖子:)
支持DotNet Dreamer
答案 2 :(得分:-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>
答案 3 :(得分:-3)
在dropdownlist属性中,您可以设置AutoPostBack = true。有了它,它会将帖子发送回服务器,因此可以触发事件。
哦。 sry我没看到你已经拥有它