2013-08-02 207 views
0

请看第1张图片。 enter image description here点击链接按钮后需要重新加载页面

在这个页面我使用LinkBut​​ton。 (像...... “SR001”, “sr003”,和所有)

.aspx页面中

<asp:LinkButton ID="lnkbtn" runat="server" onclick="lnkbtn_Click" 
ValidationGroup='<%# Eval("pid") %>'><%#Eval("productcode") %></asp:LinkButton> 

的.cs页

protected void lnkbtn_Click(object sender, EventArgs e) 
{ 
    int id; 
    id = Convert.ToInt32(((LinkButton)sender).ValidationGroup.ToString()); 
    string abc = "http://development.in/prod-more-info.aspx?pid=" + id; 
    Response.Write("<script>window.open('" + abc.ToString() + "','_blank');</script>"); 
} 

现在,当我在短声此链接按钮进程成功工作。

但..............

我的设计是通过这个过程打扰,看一下第2图像..

enter image description here

我该如何解决这个问题?

请帮助我....

回答

2

做一个原始的Response.Write是不可取的,因为你是从字面上只是附加内容到响应流。

如果要确保脚本显示在正确的位置并执行,应该使用ClientScriptManager.RegisterStartupScript来代替。

ClientScriptManager cs = Page.ClientScript; 

if (!cs.IsStartupScriptRegistered(this.GetType(), "MoreInfoPopup")) 
{ 
    int id; 
    id = Convert.ToInt32(((LinkButton)sender).ValidationGroup.ToString()); 
    string abc = "http://development.in/prod-more-info.aspx?pid=" + id; 
    string script = String.Format("<script>window.open('{0}','_blank');</script>",abc); 
    cs.RegisterStartupScript(this.GetType(), "MoreInfoPopup", script); 
} 
+0

感谢约什, 它的工作。 :) –

+0

@RajanVachhani - 没问题:) – Josh

+0

嗨,我已经尝试过本地和工作正常,但是当我在服务器上使它联机时,它不工作.. –

0

你只是想重新加载页面,一旦按钮被点击?如果是这样,请执行response redirectRequest.Url.AbsolutePath

代码:

Response.Redirect(System.Web.HttpContext.Current.Request.Url.AbsolutePath);

+0

我曾试过这个,但它不工作,因为我使用代码Response.Write(““); –

相关问题