Having just started coding in javascript/VB.NET, I am struggling to get my Button2 onClick event to work properly.
The Code-Behind Click Event for Button1 in Page.aspx.vb:
Protected Sub _lnbComments_Click(ByVal sender As Object, ByVal e As System.EventArgs)
//Some Code that needs to run before opening Modal Page
Dim Script As String = "JavaScriptCode();"
ScriptManager.RegisterStartupScript(Me.upnToolBar, Me.upnToolBar.GetType(), "CommentsClick", Script, True)
End Sub
In the JS File:
function ShowModal(page,name,style){
var r = window.showModalDialog(page,window,style);
}
function JavaScriptCode(){
var jsButton = document.getElementById('ct100_SiteContent__hiddenBtnComments'); //I made sure ClientID is correct
jsButton.click() //This should trigger onClick event and OPEN modalPage
}
During the OnLoad of Page.aspx:
Me._hiddenBtnComments.Attributes.Add("onclick","ShowModal('SomePage.aspx','SomePage','somestyle')")
Even though only the Javascript code is being executed and the Modal Page is opened, the problem arises when the code-behind click Event does not fire after closing the Modal Page. Any thoughts on what could be wrong with the code?
The Mark-up for Button 2 in Page.aspx:
<asp:Button id="_hiddenBtnComments" runat="server" style="display:none" onclick="_hiddenBtnComments_click"></asp:Button>
The Code-Behind Click Event for Button2 in Page.aspx.vb:
Protected Sub _hiddenBtnComments_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _hiddenBtnComments.Click
//Some Code that needs to run AFTER Modal Page closes.
End Sub
EDIT: A friend recommended using window.open instead of window.showmodaldialog(), which successfully triggers the code-behind click Event. However, it is essential to stick with window.showmodaldialog as per user expectations.