嗯,我敢打赌 "This works on my machine" 就是这种情况。 .
问题是:
我的 GridView
中有一个 LinkButton
:
<asp:TemplateField HeaderText="Website">
<ItemTemplate>
<asp:LinkButton ID="L_Website" CausesValidation="true" runat="server" Text='<%# Eval("L_Website") %>'
CommandArgument="GoToWebsite" OnClientClick="return confirm('Are you sure you want to go to this Website?');"
CommandName="GoToWebsite"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
我用DataReader
填充数据:
dr["L_Website"] = Convert.ToString(reader["L_Website"]);
也许您还想查看 GoToWebsite 代码:
protected void GV_Contacts_RowCommand(object sender, GridViewCommandEventArgs e)
{
string ID = string.Empty;
string status = string.Empty;
if (e.CommandName == "Edit")
{
//code here
}
else if (e.CommandName == "View")
{
//code here
}
else if (e.CommandName == "GoToWebsite")
{
LinkButton lb = (LinkButton)e.CommandSource;
GridViewRow gvr = (GridViewRow)lb.NamingContainer;
LinkButton LinkButton = gvr.Cells[8].Controls[1] as LinkButton;
if (LinkButton.Text.Substring(0, 3) == "www")
{
System.Diagnostics.Process.Start(LinkButton.Text);
}
else
{
System.Diagnostics.Process.Start("www." + LinkButton.Text);
}
}
}
它在本地计算机上运行良好。 它被显示,如果我点击它,本地版本会进行确认,然后打开一个包含此页面的新选项卡。 在服务器(IIS 6.0)上,它也显示正确,然后如果我单击它,它也进行确认,但随后它不打开新选项卡与页面。
如果我更改 CausesValidation
,它也不起作用。
如果我没有OnClientClick
,它也不起作用。
如果我将鼠标悬停在 LinkButton
上,它会显示它进行了回发。
已经谢谢你了:)
最佳答案
您没有像“客户端/服务器”那样思考。
您正在做的是启动一个进程。这在您的本地开发计算机上正在运行并且可见,因为您坐在显示器前并且可以看到这些进程。
您很可能也在服务器上启动进程,但没有人看到它们。登录服务器并观察任务管理器。
您必须找到一个在代码的客户端而不是服务器端打开链接的解决方案。 (所有这些都可以使用 HTML 和 JavaScript 完成,无需回发。)
关于c# - ASP.Net LinkButton 在本地工作但不能在服务器上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17720493/