【发布时间】:2013-07-18 10:08:29
【问题描述】:
好吧,我敢打赌这是"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"]);
也许您还想查看 GoToWebsitecode:
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 上,它表明它会进行回发。
已经谢谢你了:)
【问题讨论】:
标签: c# asp.net postback linkbutton