Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execute some js after page_load event

Status
Not open for further replies.

Pampers

Technical User
Apr 7, 2004
1,300
0
0
AN
Hi everyone,
I have webpage (apartmentdetail.aspx) with a site.master (asp.net). After the page (with a formview for databinding) loads I want some js to be executed. It will set an html-image source (src) to that of the first loaded image. Here is the code for the controls.

Code:
<img id="imgBigImage" height="403px" width="530px" src=""/>


Code:
                <asp:ImageButton ID="ImageBtn1" runat="server" Height="60px" ImageUrl='<%#Eval("ApartmentPhotoPath")%>' 
                 Width="90px" CommandName="ImageBtn1" onmouseover="showPhoto(this);"

The jscript could look something like this:

Code:
<script language="javascript" type="text/javascript">
<!-- 
function showFirstPhoto() 
{
    var imgOrg = document.getElementById('<%=FormView3.FindControl("ImageBtn1").ClientID%>')
    var strPath = imgOrg.src
    var imgTest2 = document.getElementById("imgBigImage")
    imgTest2.src = strPath
}
-->
</script>

Question is, where and/or how to put it in my page...

Pampers [afro]
Keeping it simple can be complicated
 
Try the <body> tag's onLoad event.
Code:
<body onLoad="myfunction();">
....
</body>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks Vacunita for the reply,

I dont think there is a body-tag since it has a master-page, so it holds content-tags...

Pampers [afro]
Keeping it simple can be complicated
 
There has to be a body tag. Otherwise its not a valid HTML page.

I'm not familiar with ASP, so I'm not quite sure what a master-page is in that context. Or how it would work.

You could of course use the Onload event of the image, but that only guarantees the image has loaded, not that the entire page has loaded.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Pampers, you are comparing apples and oranges. webforms is a server framework for generating html. javascript is a scripting language that runs on the client's browser. the 2 have nothing to do with one another.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Hi jmeckley,
Thanks for the reply. I think I am aware is a difference between the framework and js. What i want to accomplish is that on the loading of a webpage some js is executed.

I was trying to add some js in the .aspx form. Didnt succeed. Then I added some code in my code-behind page and injected some js in the on load-event.

Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim imgTest As Image
        Dim strPath As String

        imgTest = FormView3.FindControl("ImageBtn1")

        strPath = imgTest.ImageUrl

        ' Initialize a stringbuilder object, much faster than string concatenation 
        Dim onloadScript As New System.Text.StringBuilder()
        onloadScript.Append("<script type='text/javascript'>")
        onloadScript.Append(vbCrLf)
        onloadScript.Append("document.getElementById('imgBigImage').src='" & strPath & "'")
        onloadScript.Append(vbCrLf)
        onloadScript.Append("</script>")


        Me.ClientScript.RegisterStartupScript(Me.GetType(), "onLoadCall", onloadScript.ToString())

    End Sub

Pampers [afro]
Keeping it simple can be complicated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top