Last post Apr 13, 2012 10:50 AM by sconly
Apr 13, 2012 09:36 AM|sconly|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)
Is the code completely wrong, or just the wrong way to go about it? Please advise.
Apr 13, 2012 09:52 AM|ramiramilu|LINK
lbnCtrlTitleChange_ctrl.Attributes.Add("OnClick", "aspnetForm.target ='_blank';")
Apr 13, 2012 09:54 AM|somnathmali|LINK
Rather than doing that on server side, you should check the textbox value at client side
<asp:LinkButton OnClientClick="return fooFunction()" ..
and return false.
BTW, I dont see use of linkbutton, you can go with hyperlink control if you dont want postback.
Apr 13, 2012 10:16 AM|sconly|LINK
Thanks for the reply (ramiramilu) but that doesn't open a new tab/window.
Apr 13, 2012 10:20 AM|oblomov86|LINK
Apr 13, 2012 10:50 AM|sconly|LINK
I used this little nugget...