By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

Unable to call javascript function AND post with same buttom

P: n/a
I want to execute a javascript function that will set a value in the
parent window from the child widow where its called and then post the
form to the server. I seem to be able to execute one or the other but
not both. The child page (html) code is:

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="AddKeyWord.aspx.vb" Inherits="ComponentSearch.AddKeyWord"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=""
<script language='javascript'>
function WriteBack() {
if (document.forms[0].TextBox_KeyWord) {

document.writeln(opener.document.forms[0].TextBox_KeyWords.value =
opener.document.forms[0].TextBox_KeyWords.value + ' ' +
document.forms[0].TextBox_KeyWord.value); };
return true;
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:textbox id="TextBox_KeyWord" style="Z-INDEX: 101; LEFT: 96px;
POSITION: absolute; TOP: 64px"
runat="server" Width="328px" Height="24px"></asp:textbox><asp:label
id="Label1" style="Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP:
32px" runat="server"
Width="120px" Height="24px">Key Word to Add</asp:label><asp:button
id="Button_Add" onclick="WriteBack" style="Z-INDEX: 103; LEFT: 192px;
POSITION: absolute; TOP: 96px"
runat="server" Width="56px" Text="Add"></asp:button><asp:button
id="Button_Cancel" style="Z-INDEX: 104; LEFT: 280px; POSITION:
absolute; TOP: 96px"
runat="server" Width="51" Height="24"
Text="Cancel"></asp:button><asp:label id="Label_ErrorMessage"
style="Z-INDEX: 105; LEFT: 104px; POSITION: absolute; TOP: 136px"
runat="server" Width="328px" Height="24px" Visible="False"
The VB.NET Codebehind function is named the same as the javascript
function (a technique that was detailed in this group) and the entire
codebehind code is:

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
Button_Add.Attributes.Add("OnClick", "javascript:WriteBack();")

End Sub

Public Sub WriteBack(ByVal sender As System.Object, ByVal e As
If TextBox_KeyWord.Text & "" > "" Then
PostKeyWord(OpenConnection, Session("SYSTEM_NAME"),
Label_ErrorMessage.Visible = False
Label_ErrorMessage.Text = "Enter a keyword to add"
Label_ErrorMessage.Visible = True
End If
End Sub

Why won't the client run both the javascript and then execute the
writeback sub in the code behind?? If I comment out the line
Button_Add.Attributes.Add("OnClick", "javascript:WriteBack();") in the
codebehind the WriteBack sub in the codebehind is executed. If I leave
it in the javascript is executed and the value is written back to the
parent properly, but not the codebehind is executed. Any help would be
greatly appreciated. Thanks,

Prescott ...

Oct 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.