How do i programmatically (in the codebehind) add OnClientClick="aspnetForm.target ='_blank';" to a LinkButton (lbnCtrlTitleChange_ctrl)?
I want the LinkButton to open a new window/tab but only if a textbox has got text in it.
I have the following code but it doesn't seem to be working.
Protected Sub lbnCtrlTitleChange_ctrl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbnCtrlTitleChange_ctrl.Click
If txtControlID_ctrl.Text <> "" Then
lbnCtrlTitleChange_ctrl.Attributes.Add("OnClientClick", "aspnetForm.target ='_blank';")
Response.Redirect("~/ControlChange.aspx?CtrlID=" & txtControlID_ctrl.Text)
End If
End Sub
Is the code completely wrong, or just the wrong way to go about it? Please advise.
sconly
Member
62 Points
112 Posts
LinkButton OnClientClick code help, please.
Apr 13, 2012 08:36 AM|LINK
How do i programmatically (in the codebehind) add OnClientClick="aspnetForm.target ='_blank';" to a LinkButton (lbnCtrlTitleChange_ctrl)?
I want the LinkButton to open a new window/tab but only if a textbox has got text in it.
I have the following code but it doesn't seem to be working.
Protected Sub lbnCtrlTitleChange_ctrl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbnCtrlTitleChange_ctrl.Click If txtControlID_ctrl.Text <> "" Then lbnCtrlTitleChange_ctrl.Attributes.Add("OnClientClick", "aspnetForm.target ='_blank';") Response.Redirect("~/ControlChange.aspx?CtrlID=" & txtControlID_ctrl.Text) End If End SubIs the code completely wrong, or just the wrong way to go about it? Please advise.
Thanks
ramiramilu
All-Star
95275 Points
14072 Posts
Re: LinkButton OnClientClick code help, please.
Apr 13, 2012 08:52 AM|LINK
lbnCtrlTitleChange_ctrl.Attributes.Add("OnClick", "aspnetForm.target ='_blank';")
onclientclick is asp.net property...you need to use onclick javascript to define client event...
thanks,
JumpStart
somnathmali
Contributor
2816 Points
450 Posts
Re: LinkButton OnClientClick code help, please.
Apr 13, 2012 08:54 AM|LINK
Rather than doing that on server side, you should check the textbox value at client side
<asp:LinkButton OnClientClick="return fooFunction()" ..
Javascript fooFunction actually check the textbox value , if that is not null then open new window using "window.open"...
and return false.
BTW, I dont see use of linkbutton, you can go with hyperlink control if you dont want postback.
.NET Developer , Pune INDIA.
Please Mark As Answer If my reply helped you.
sconly
Member
62 Points
112 Posts
Re: LinkButton OnClientClick code help, please.
Apr 13, 2012 09:16 AM|LINK
Thanks for the reply (ramiramilu) but that doesn't open a new tab/window.
oblomov86
Member
280 Points
76 Posts
Re: LinkButton OnClientClick code help, please.
Apr 13, 2012 09:20 AM|LINK
Use this http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
sconly
Member
62 Points
112 Posts
Re: LinkButton OnClientClick code help, please.
Apr 13, 2012 09:50 AM|LINK
I used this little nugget...
http://www.codeproject.com/Tips/317410/Response-Redirect-into-a-new-window