Linkbutton href url

自古美人都是妖i 提交于 2019-12-08 05:36:08

问题


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:


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



来源:https://stackoverflow.com/questions/10172567/linkbutton-href-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!