Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Using VB.NET Code and Javascript with one click

Hi,

I have a problem when trying to use VB.NET Code and afterwards trying to execute Javascript-Code.

I open a new popup-website using javascript, the user inputs some data and clicks on save. First the VB.NET Code should save the data into a database, afterwards the JS-Code should refresh the original web-site and close the popup-website.

I'm successfully able to either save the data or refresh the website and close the popup-website, but not doing this at the same time.

I've tried using
pb_Apply.Attributes.Add("onclick", "javascript:opener.location.reload();self.close()")

But when using this it doesn't execute
Protected Sub pb_Apply_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pb_Apply.Click

Thanks in advance
[823 byte] By [JC_Denton2002] at [2007-11-11 6:59:39]
# 1 Re: Using VB.NET Code and Javascript with one click
Please check it out.
In Page_Load of Pop-Up Windows

pb_Apply.Attributes.Add("onclick"," return SaveNCloseJSFunc();")

SaveNCloseJSFunc() is JavaScript Function written in HTML.
SaveNCloseJSFunc()

<script language="javascript">
function SaveNCloseJSFunc(){
<% Save() %>;
//window.returnValue='aa';
if(opener != null){
opener.location.href=opener.location.href;
}
window.close();
}
</script>

Save() Function is your server-side script.

I hope it would help.
Let me know the result.
Sync at 2007-11-11 23:14:00 >
# 2 Re: Using VB.NET Code and Javascript with one click
It's working great, thanks for the advice!
JC_Denton2002 at 2007-11-11 23:15:06 >
# 3 Re: Using VB.NET Code and Javascript with one click
However, there's one little thing that I still want to get rid of

The server-side function Save() is also executed when loading the page, but this should only happen if I click on the save-button of course
JC_Denton2002 at 2007-11-11 23:16:05 >
# 4 Re: Using VB.NET Code and Javascript with one click
Yeah. Friend.
so that it's better if you check IsPageLoad in Save Method.
Sync at 2007-11-11 23:17:04 >
# 5 Re: Using VB.NET Code and Javascript with one click
That's a great idea, but we're migrating to VS.2005 and it doesn't seems to recognize IsPageLoad anymore.

The methods I found don't seem to be working for my case (the page needs to do several PostBack's):
http://msdn2.microsoft.com/en-us/library/ms178141

I tried several things with the Validators, but it doesn't seem they can trigger a IsValid when a button is clicked.
JC_Denton2002 at 2007-11-11 23:18:03 >