Execute Javascript AFTER click event

  • Thread starter Thread starter Ian Kelly
  • Start date Start date
I

Ian Kelly

Hi All,
I have an .net form that is split into two frames. The left frame has a
tree that displays a list of all the customers. The right frame displays
the appropriate clients information. When the save button is pressed on the
right frame, I want to update the tree in the left frame AFTER saving all
the data as the changes to the right frame may affect how the tree is
displayed. I tried using the following:

btnSave.Attributes("onclick") = "top.frames['search'].location.href =
'SearchTree.aspx';"

The only issue is that the above javascript executes BEFORE the server side
click event. So what I need to be able to do is either

1) call a javascript from vb.net whenever I want OR
2) without javascript, refresh a frame from another frame OR
3) somehow have the clientside script execute AFTER the serverside
script


Any help, with examples, would be greatly appreciated.

Thanks
Ian
 
Hi Eliyahu,
Thanks for your suggestion. I should have given some info on my background.
I am a VB 6.0 programmer. VB.NET is very new to me. I think I got most of
what you were suggesting, but could I get some more detail. Sorry.

Ian
Eliyahu Goldin said:
Ian,

3) is the way to go. Make a hidden input for passing instructions from
server to client. Make a client-side <body .. onload=..> event that will
read the input and handle the instruction if any. Normally, the input will
be empty. When you want to tell the client to update the tree, pass a word
"UPDATETREE". The client side onload event will get the word and execute
top.frames['search'].location.href = 'SearchTree.aspx';

Eliyahu

Ian Kelly said:
Hi All,
I have an .net form that is split into two frames. The left frame has a
tree that displays a list of all the customers. The right frame displays
the appropriate clients information. When the save button is pressed on the
right frame, I want to update the tree in the left frame AFTER saving all
the data as the changes to the right frame may affect how the tree is
displayed. I tried using the following:

btnSave.Attributes("onclick") = "top.frames['search'].location.href =
'SearchTree.aspx';"

The only issue is that the above javascript executes BEFORE the server side
click event. So what I need to be able to do is either

1) call a javascript from vb.net whenever I want OR
2) without javascript, refresh a frame from another frame OR
3) somehow have the clientside script execute AFTER the serverside
script


Any help, with examples, would be greatly appreciated.

Thanks
Ian
 
Ian,

3) is the way to go. Make a hidden input for passing instructions from
server to client. Make a client-side <body .. onload=..> event that will
read the input and handle the instruction if any. Normally, the input will
be empty. When you want to tell the client to update the tree, pass a word
"UPDATETREE". The client side onload event will get the word and execute
top.frames['search'].location.href = 'SearchTree.aspx';

Eliyahu
 
Ian,

Put in your .aspx file just before the </form> tag a line:
<input type=hidden id=inhAction runat=server>
Here you will pass action instructions from server to client.
After switching to design view and back to html view it will add a
HtmlInputHidden control named inhAction to yoour code behind.

In the Page_Load server event put a line:
inhAction.Value=""
This will preset the action to empty string.

At the end of your server-side event that handles the save button click put
a line:
inhAction.Value="UPDATETREE"

Go back to the .aspx page and make your <body> looking as
<body onload="handleAction()">

In the <head> section of the .aspx page add a javascript::
<script language="javascript">
function handleAction(){
if (Form1.inhAction.value=="UPDATETREE")
top.frames['search'].location.href = 'SearchTree.aspx';
}
</script>

That's about it.

Eliyahu

Ian Kelly said:
Hi Eliyahu,
Thanks for your suggestion. I should have given some info on my background.
I am a VB 6.0 programmer. VB.NET is very new to me. I think I got most of
what you were suggesting, but could I get some more detail. Sorry.

Ian
Eliyahu Goldin said:
Ian,

3) is the way to go. Make a hidden input for passing instructions from
server to client. Make a client-side <body .. onload=..> event that will
read the input and handle the instruction if any. Normally, the input will
be empty. When you want to tell the client to update the tree, pass a word
"UPDATETREE". The client side onload event will get the word and execute
top.frames['search'].location.href = 'SearchTree.aspx';

Eliyahu

Ian Kelly said:
Hi All,
I have an .net form that is split into two frames. The left frame has a
tree that displays a list of all the customers. The right frame displays
the appropriate clients information. When the save button is pressed
on
the
right frame, I want to update the tree in the left frame AFTER saving all
the data as the changes to the right frame may affect how the tree is
displayed. I tried using the following:

btnSave.Attributes("onclick") = "top.frames['search'].location.href =
'SearchTree.aspx';"

The only issue is that the above javascript executes BEFORE the server side
click event. So what I need to be able to do is either

1) call a javascript from vb.net whenever I want OR
2) without javascript, refresh a frame from another frame OR
3) somehow have the clientside script execute AFTER the serverside
script


Any help, with examples, would be greatly appreciated.

Thanks
Ian
 
Eliyahu,
I just got in and tried this. It works VERY well.

Thank you very much.

Ian
Eliyahu Goldin said:
Ian,

Put in your .aspx file just before the </form> tag a line:
<input type=hidden id=inhAction runat=server>
Here you will pass action instructions from server to client.
After switching to design view and back to html view it will add a
HtmlInputHidden control named inhAction to yoour code behind.

In the Page_Load server event put a line:
inhAction.Value=""
This will preset the action to empty string.

At the end of your server-side event that handles the save button click
put
a line:
inhAction.Value="UPDATETREE"

Go back to the .aspx page and make your <body> looking as
<body onload="handleAction()">

In the <head> section of the .aspx page add a javascript::
<script language="javascript">
function handleAction(){
if (Form1.inhAction.value=="UPDATETREE")
top.frames['search'].location.href = 'SearchTree.aspx';
}
</script>

That's about it.

Eliyahu

Ian Kelly said:
Hi Eliyahu,
Thanks for your suggestion. I should have given some info on my background.
I am a VB 6.0 programmer. VB.NET is very new to me. I think I got most of
what you were suggesting, but could I get some more detail. Sorry.

Ian
Eliyahu Goldin said:
Ian,

3) is the way to go. Make a hidden input for passing instructions from
server to client. Make a client-side <body .. onload=..> event that
will
read the input and handle the instruction if any. Normally, the input will
be empty. When you want to tell the client to update the tree, pass a word
"UPDATETREE". The client side onload event will get the word and
execute
top.frames['search'].location.href = 'SearchTree.aspx';

Eliyahu

Hi All,
I have an .net form that is split into two frames. The left frame has a
tree that displays a list of all the customers. The right frame displays
the appropriate clients information. When the save button is pressed on
the
right frame, I want to update the tree in the left frame AFTER saving all
the data as the changes to the right frame may affect how the tree is
displayed. I tried using the following:

btnSave.Attributes("onclick") = "top.frames['search'].location.href =
'SearchTree.aspx';"

The only issue is that the above javascript executes BEFORE the server
side
click event. So what I need to be able to do is either

1) call a javascript from vb.net whenever I want OR
2) without javascript, refresh a frame from another frame OR
3) somehow have the clientside script execute AFTER the serverside
script


Any help, with examples, would be greatly appreciated.

Thanks
Ian
 
Back
Top