C# 停止双向回发
这就是我正在做的。我在创建的gridview的标题行中创建了两个按钮。按钮有+页和-页。当点击-page时,我移除分页,所有的数据都进入页面,并且-page消失,+page在那里 我的问题来了当我点击+页面时,我必须重复回发,因为我的一行数据消失了。我将在下面提供代码。我能做些什么来解决这个问题C# 停止双向回发,c#,asp.net,javascript,vb.net,updatepanel,C#,Asp.net,Javascript,Vb.net,Updatepanel,这就是我正在做的。我在创建的gridview的标题行中创建了两个按钮。按钮有+页和-页。当点击-page时,我移除分页,所有的数据都进入页面,并且-page消失,+page在那里 我的问题来了当我点击+页面时,我必须重复回发,因为我的一行数据消失了。我将在下面提供代码。我能做些什么来解决这个问题 Dim bttnrempag As New Button bttnrempag.ID = "bttnrempag" bttnrempag.Text = " Paging"
Dim bttnrempag As New Button
bttnrempag.ID = "bttnrempag"
bttnrempag.Text = " Paging"
bttnrempag.CssClass = "bttnMinEG"
bttnrempag.ValidationGroup = "alone"
bttnrempag.Attributes.Add("onclick", "return Paging('1')")
Dim bttnallowpag As New Button
bttnallowpag.ID = "bttnallowpag"
bttnallowpag.Text = " Paging"
bttnallowpag.ValidationGroup = "alone"
bttnallowpag.CssClass = "bttnAddEG"
bttnallowpag.Attributes.Add("onclick", "return Paging('0')")
--------------按钮的添加方式--------------------------------------------
Dim row As New GridViewRow(-1, -1, DataControlRowType.Separator, DataControlRowState.Normal)
row.Cells.Add(cell)
cell.Controls.Add(bttnrempag) '36
cell.Controls.Add(bttnallowpag)
function Paging(remove) {
var gridView = $get('<%=Gridview1.ClientID %>');
var txt2 = $get('<%=TextBox2.ClientID %>');
if (remove == '1') {
txt2.value = '1';
__doPostBack('<%=UpdatePanel1.ClientID %>', '');
return false;
}
else {
txt2.value = '0';
__doPostBack('<%=UpdatePanel1.ClientID %>', '');
return false;
}
----------------------------------------------------------------------------------------------------
Dim row As New GridViewRow(-1, -1, DataControlRowType.Separator, DataControlRowState.Normal)
row.Cells.Add(cell)
cell.Controls.Add(bttnrempag) '36
cell.Controls.Add(bttnallowpag)
function Paging(remove) {
var gridView = $get('<%=Gridview1.ClientID %>');
var txt2 = $get('<%=TextBox2.ClientID %>');
if (remove == '1') {
txt2.value = '1';
__doPostBack('<%=UpdatePanel1.ClientID %>', '');
return false;
}
else {
txt2.value = '0';
__doPostBack('<%=UpdatePanel1.ClientID %>', '');
return false;
}
功能分页(删除){
var gridView=$get(“”);
var txt2=$get(“”);
如果(删除=='1'){
txt2.value='1';
__doPostBack('','');
返回false;
}
否则{
txt2.value='0';
__doPostBack('','');
返回false;
}
已编辑
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate >
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
DataSourceID="SqlDataSource1" Font-Names="Comic Sans MS" Font-Size="XX-Small"
Caption = '<table border="" width="100%" cellpadding="3" cellspacing="0" bgcolor="#4A3C8C"><tr><td style = "font-size:X-large;font-family:Arial CE;color:White"><b>Ordering/Receiving Log</u></td></tr></table>'
Font-Bold="True" PageSize="15" >
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
Bound Data
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<EmptyDataTemplate>
<head>
<meta http-equiv="refresh" content="5;URL=/Corporate_newpo/ReceivingLog.aspx?">
</head>
<script type="text/javascript" >
var count = 6;
var counter = setInterval("timer()", 1000); //1000 will run it every 1 second
function timer() {
count = count - 1;
if (count <= 0) {
clearInterval(counter);
//counter ended, do something here
return;
}
$get("timer").innerHTML = "The Table will Reload in " + count + " secs";
}
</script>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Large"
ForeColor="#993333" Text="No Data was Found for the Selected Filter"></asp:Label><br /><br />
<span id="timer" style="font-size:medium;color:blue"></span>
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
<PagerTemplate>
<small 12px""="" style="font-size:xx-small; padding-right">Go To Page</small>
<asp:DropDownList ID="ddlPageSelector" runat="server" AutoPostBack="true"
Font-Size="XX-Small" Height="19px" Width="36px">
</asp:DropDownList>
<asp:ImageButton ID="btnFirst" runat="server" CommandArgument="First"
CommandName="Page" SkinID="pagefirst" />
<asp:ImageButton ID="btnPrevious" runat="server" CommandArgument="Prev"
CommandName="Page" SkinID="pageprev" />
<asp:ImageButton ID="btnNext" runat="server" CommandArgument="Next"
CommandName="Page" SkinID="pagenext" />
<asp:ImageButton ID="btnLast" runat="server" CommandArgument="Last"
CommandName="Page" SkinID="pagelast" />
</PagerTemplate>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
绑定数据
var计数=6;
var counter=setInterval(“timer()”,1000);//1000将每1秒运行一次
函数计时器(){
计数=计数-1;
如果(count我怀疑这是因为您调用了“\uu doPostBack”方法。按钮的正常默认单击行为将执行异步回发,您可能会让它再执行一次。尝试删除它,看看它是如何运行的。您能试着在RowDataBound事件声明中的按钮上放置click属性吗
干杯。试试这个,(我不知道你为什么要使用javascript):
尝试更改您的和,以获得一些可能有帮助的错误行为。如果您有标签,请继续阅读我的工作
在我的具体案例中,这只发生在一些服务器上(在一些客户端站点),而不是其他服务器上,因此我找不到代码的任何具体问题。我的解决方法是使用javascript单击事件将我的标记更改为常规标记,该事件将调用一个函数来执行回发,就像您的Paging()函数一样
出于某种原因,我发现,如果confirm()返回false,则带有客户端onclick返回事件:confirm('you sure?');的将停止回发,但返回false的方式与分页()相同手动调用uu doPostBack后的函数不会始终阻止页面再次发回。您必须为ImageButtons提供一个图像。否则,呈现的HTML将生成一个
标记,呈现后会导致回发。试试看。我找到了一个很好的解决方案,效果非常好.它确实附加了自己的处理程序,但我想这也可以解决
using System.Linq;
private void GridView_OnItemDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var buttons = e.Row.Cells.OfType<DataControlFieldCell>().SelectMany(item => item.Controls.OfType<ImageButton>());
foreach (ImageButton imageButton in buttons)
{
var argument = imageButton.CommandName + "$" + imageButton.CommandArgument;
imageButton.OnClientClick = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView, argument) + "; return false;";
}
}
}
使用System.Linq;
私有void GridView\u OnItemDataBound(对象发送方,GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
var buttons=e.Row.Cells.OfType().SelectMany(item=>item.Controls.OfType());
foreach(按钮中的ImageButton ImageButton)
{
var参数=imageButton.CommandName+“$”+imageButton.CommandArgument;
imageButton.OnClientClick=this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView,参数)+“返回false;”;
}
}
}
请查看页面上呈现的html:
每次它出现的时候
<img src=""/>
但是通过return false
他应该阻止默认行为。嗯……显示更多代码如何?例如,在UpdatePanel中如何构造控件以及如何进行数据绑定。客户端“分页(删除)”函数除了为您提供文本框值的视觉线索外,实际上并不需要。好的。我为您添加了代码,我正在听-您可能有点道理。我不认为在这种情况下,return false将阻止回发。将显式调用u doPostBack方法,该方法将调用form.submit()。页面已经提交,返回false不会取消此行为。@Phaedrus您是对的。但它只执行部分回发。而不是完全回发。但是,是的-返回false是毫无意义的。@Eric-标记用于实际使用的内容。asp.net标记涵盖vb.net和c#用于您的目的。您提供的链接指出了原因它正在发生(但我不知道为什么它只会出现在某些服务器上…除非指向映像的路径无效或ASP.NET没有访问映像的权限…如果您在虚拟目录中开发,但部署到web应用程序根目录,则映像的路径无效总是会发生。
Page.Request.Params["__EVENTTARGET"];