calling javascript from code-behind

  • Thread starter Thread starter Peter Bons
  • Start date Start date
P

Peter Bons

Hi all,

I have an asp.net page with a button that has a javascript onclick method
attached to it to display a modal dialog like this:

If reportHasParameters Then
'add client side onclick() event handler to display the popup dialog for
entering parametervalues
btnChangeParameters.Attributes.Add("onclick",
String.Format("window.showModalDialog
('ParameterPopup.aspx?reportID={0}',
null,'status:no;dialogWidth:640px;dialogHeight:480px;dialogHide:true;help:no;scroll:no');",
Request.QueryString.Item(1)))
Else
btnChangeParameters.Visible = False
End If

this works all right.

Now, the next step is, when te page is loaded the first(!) time, and the
value of the boolean reportHasParameters is TRUE the dialog has to show up
as well.

How can I do that? putting the javascript call in the onload property of the
body tag isn't working because at that time I do not know the value of
reportHasParameters and because then the javascript code is executed every
time a reload takes place.

Somewhere in my code behind, at the Page_Load event I would like to execute
the javascript code like this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If reportHasParameters Then
'add client side onclick() event handler to display the popup dialog for
entering parametervalues
btnChangeParameters.Attributes.Add("onclick",
String.Format("window.showModalDialog
('ParameterPopup.aspx?reportID={0}',
null,'status:no;dialogWidth:640px;dialogHeight:480px;dialogHide:true;help:no;scroll:no');",
Request.QueryString.Item(1)))

If Not IsPostBack Then
'execute javascript code to show modal dialog
End If
Else
btnChangeParameters.Visible = False
End If

Does someone knows how to accomplish this?

Kind regards and thanx for answering in advance,
Peter
 
popup blockers (xp-sp2) will prevent this code from working.

-- bruce (sqlwork.com)
 
That's not a serious problem as it will run in an controlled intranet, se we
can set policies to prevent the blocking of te code
 
Back
Top