|
-
Aug 4th, 2005, 10:59 PM
#1
Thread Starter
Addicted Member
webcontrol button with script attribute
how can I make the button_click to execute first before the script that I added in the buttons's attribute
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim scriptOk As String
scriptOk = "window.returnValue = true; " _
& " window.dialogArguments.strName = window.document.all.MyFile.value; " _
& " window.close();"
btnOk.Attributes.Add("onclick", scriptOk)
btnCancel.Attributes.Add("onclick", "window.returnValue = false;window.close();")
End Sub
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
'Response.Write("hello")
'MyFile.PostedFile.SaveAs("")
End Sub
myFile is an htmlinputfile server control, I want the file to be uploaded first before the web page execute the script to close the window
Thanks,
Jewel
-
Aug 6th, 2005, 12:12 PM
#2
Frenzied Member
Re: webcontrol button with script attribute
You can't do what you are saying the method you suggest. The client-side onclick event will always fire before the page is Posted Back and the server-side click event is fired.
What you want to do is remove the client-side onclick event and add some code to the server-side event that uses the Page's RegisterStartupScript method.
This method executes client-side code as soon as the page reloads i.e. after your server-side Click event fires. It is used as below:
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnCancel.Attributes.Add("onclick", "window.returnValue = false; window.close();")
End Sub
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
If MyFile.PostedFile.ContentLength > 0 Then
'Response.Write("hello")
'MyFile.PostedFile.SaveAs("")
RegisterStartupScript("image_uploaded", "window.returnValue = true; window.close();")
End If
End Sub
The RegisterStartupScript has two arguments - the first is a unique key so it can be referenced in your code and the second is the client-side script you want to execute.
Let me know if you have any problems.
DJ
If I have been helpful please rate my post. If I haven't tell me!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|