回滚__doPostBack
关于回滚__doPostBack('dopostbackbtn','')出错的问题?有谁知道吗?详情请进......
我有一服务器按钮ID号为:dopostbackbtn,我在单击事情中写了许多代码。
System.Text.StringBuilder sb=new System.Text.StringBuilder();
sb.Append("<a href=\"javascript:__doPostBack('dopostbackbtn','')\">首页</A>");
ageInfo.Text=sb.ToString();
我想点击首页就去执行dopostbackbtn按钮中的代码怎么不行呢?
1楼
http://www.cnblogs.com/lovecherry/archive/2005/04/18/139634.html
2楼
方式了楼上的,都不行!
3楼
up....
4楼
sb.Append("<A href='#' onclick=\"document.getElementById('Button1').click()\">"+min.ToString()+"</A> ");
我点击上面的 min超链接现在可以回滚到后台事件了,多谢 回复人: LoveCherry(论成败,人生豪迈;大不了,重头再来!^_^) ,我现在回滚的时候能候在后台Button1事件中得到点击的超链接min文本字符值如何得到?
谢谢 。
5楼
answer is no, you are on the wrong track, use a linkbutton instead
<asp:LinkButton id="lb" runat="server" OnClick="YourEventHandler" />
..
lb.Text = min;
6楼
思归老大:我其实就是想实现
http://bbs.openlab.net.cn/ShowForum.aspx?ForumID=31 的翻页功能:
总页数 41 第 1 页 [共有 807 条记录] 1 2 3 4 5 » ... 末页 »
点击第几页时我希望到后台去执行代码.有办法吗?
7楼
I already answered you, use LinkButton
<asp:PlaceHolder id="ph" runat="server" />
for (int i=0; i < .. ; i++)
{
LinkButton lb = new LinkButton();
lb.Click += new EventHandler(YourMethodHere);
lb.ID = i.ToString();
lb.Text = (i+1).ToString();
ph.Controls.Add(lb);
ph.Controls.Add( new LiteralControl(" "));
}
void YourMethodHere(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
//...
}
8楼
学习 楼上强人
9楼
思归老大:我按你的试了,当我点击第几页时事情是回滚,可并没有执行代码,反而一点击那个ph就从页面上消失了,怎么回事?
while(min<=max)
{
LinkButton lb = new LinkButton();
lb.Click += new EventHandler(gopagex);
lb.ID = min.ToString();
lb.Text = min.ToString();
ph.Controls.Add(lb);
ph.Controls.Add( new LiteralControl(" "));
//sb.Append("<asp:LinkButton id='lb"+min.ToString()+"' runat='server' OnClick='Button1_Click'>"+min.ToString()+"</asp:LinkButton> ");
//sb.Append("<A href='#' onclick=\"document.getElementById('Button1').click()\">"+min.ToString()+"</A> ");
min=min+1;
}
private void gopagex(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
ViewState["current_page"]=Convert.ToInt32(lb.Text.Trim());//当前页Convert.ToInt32(Request["__EVENTARGUMENT" ].ToString());(用记户所点击的超链接)
string commstring=SplitPage.StratDetachPage((int)ViewState["pagesize"],(int)ViewState["current_page"],(int)ViewState["count"],"menu4","keyid,img","writetime",false,ViewState["where"].ToString());
DataTable tb=DbProvider.Instance().GetRecordsBySql(commstring);
ImagesData.DataSource=tb;
ImagesData.DataBind();
SetPages();
}
10楼
you need to re-create the buttons upon postback
11楼
是不是点击linkbutton时要重新建立这些linkbuttion?
可是点击它时并没有执行lb.Click += new EventHandler(gopagex);
中的 gopagex过程啊?
12楼
<form runat="server">
<asp:PlaceHolder id="ph" runat="server" />
</form>
<script language="C#" runat="server">
void CreateLinks()
{
for (int i=0; i<10; i++)
{
LinkButton lb = new LinkButton();
lb.Click += new EventHandler(YourMethodHere);
lb.ID = i.ToString();
lb.Text = (i+1).ToString();
ph.Controls.Add(lb);
ph.Controls.Add( new LiteralControl(" "));
}
}
void Page_Load(Object sender, EventArgs e)
{
CreateLinks();
}
void YourMethodHere(Object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
Response.Write(lb.Text + " is clicked");
}
</script>
13楼
doPostBack 不是回滚,只是提交服务端而已。实际就是submit
14楼