ASP.Net链接按钮可以在本地工作,但不能在服务器上工作



好吧,我打赌这是"这在我的机器上工作"的情况。

问题是:

我的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"]);

也许你也想看看GoToWeb站点代码:

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完成,不需要PostBack。)

最新更新