开发者

calling javascript function from .net codebehind with a value

I am trying to call a javascript function from asp.net codebehind using onclientclick for a linkbutton. Code is 开发者_如何转开发like this:

string x = "redirecttoimagepage"+"("+ y+")";//y has an int value i need and it varies
lnkimagepage.OnClientClick = x;

i need to use the value y in the javascript function for using.

 function redirecttoimagepage(variable)
{
var strURL = "Subpages.aspx?tabID="+variable;
window.open(strURL,"_blank");
return true;
}

Right now, with the code i have shared, it doesnt do anything. After the link is clicked, it stays in the same page. What am i doing wrong? Appreciate all your help guys. Thanks a lot!


string x = "redirecttoimagepage"+"('"+ y+"')";
lnkimagepage.Attributes.Add("onclick",x);

EDITED

in addition, just noticed that lnkimagepage is a LinkButton so it will be hard to invoke redirecttoimagepage script as LinkButtons are already associated with __doPostBack jscript. use HyperLink instead of LinkButton


I am trying to call a javascript function from asp.net codebehind using onclientclick for a linkbutton. Code is like this:

Your doing it wrong. The HTTP model is a model of requests. The page talks to the server not the other way around.

If you truly need a bi-directional communication channel use WebSockets


string x = "redirecttoimagepage"+"('"+ y+"')"; 
lnkimagepage.Attributes.Add("onclick",x);

**in javascript**
window.open("PageName.aspx");


I think you must specify complete url with window.open not just page name.....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜