Linkbutton href url

2019-06-04 06:04发布

I have a loop in my code with dynamic linkbuttons and I want to set the OnClientClick property to open up the link in a new browser window. It sounds simple but I am having a bit of trouble getting it to work.

lbUrl = new LinkButton();
lbUrl.Text = r["Url"].ToString();

// r["Url"] is Datarow
lbUrl.OnClientClick = "location.href=" + r["Url"].ToString();

Any ideas?

1条回答
Evening l夕情丶
2楼-- · 2019-06-04 06:33

window.open() will open the link in a new browser tab/window

lbUrl.OnClientClick = String.Format("window.open('{0}')", r["Url"]);

Ensure your URL is an Absolute URL

查看更多
登录 后发表回答