Protected Sub lnkContractors_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkContractors.Click
If Context.User.IsInRole("HOD") Then
lnkContractors.OnClientClick = "PopupCenter('Juniors.aspx', 'myPop1',820,500);"
ElseIf Context.User.IsInRole("Contractor") Then
lnkContractors.OnClientClick = "PopupCenter('Contractors.aspx', 'myPop1',820,500);"
End If
End Sub
I have a LinkButton in my master page and the linkbutton is inside an UpdatePanel. The problem is, when I click the linkbutton the first time, the page only refreshes but the popup window does not open. I have to click the second time to get popup window open.
function PopupCenter(pageURL, title, w, h) {
var left = (screen.width / 2) - (w / 2);
var top = (screen.height / 2) - (h / 2);
var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
}
You need to state the
OnClientClickJavaScript function on Page Load. Not in the buttonsOnClickevent. Since the decision to add a client-side function to your button needs to happen soon as the page is loaded.Just move the code you currently have in your button click event to the Page Load event and see what happens.