|
-
Jun 7th, 2012, 03:37 PM
#1
Thread Starter
Hyperactive Member
Handling onclick event issue
Hello Good folks,
I am having a small problem and I have been trying to figure this out for the last 2 days...very frustrated.
There is a server side button control <asp:Button/> on my .aspx page. There are two event handlers on this control. One is clientside (in Javascript) and server side. When the user clicks on the button only clientside script should be fired (not the server side).the user enters some input into a text box and clicks the button again. Now only the server side script should be executed. Client side script should not be executed.
So far, everything works but for some reason after the server side script get executed again the clientside script gets executed. I have to no clue why this is happening...can someone advise me please
Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/QRMDMS.Master" trace="false" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs" Inherits="FHLBSF.QRMDMS.WebUI.WebForm7" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<script type="text/javascript">
function AddClientSide() {
alert("started the client side script");
var varLabelBSISTypes = document.getElementById("<%=LabelBSISType.ClientID%>");
varLabelBSISTypes.style.display = "block";
varLabelBSISTypes.style.visibility = "visible";
var varTextBoxBSISType = document.getElementById("<%=TextBoxBSISType.ClientID%>");
varTextBoxBSISType.style.display = "block";
varTextBoxBSISType.style.visibility = "visible";
var varButtonAdd = document.getElementById("<%=ButtonAdd.ClientID%>");
var varproperty = varButtonAdd.getAttribute("value");
if (varproperty == "Save") {
alert("button now is in save mode");
varButtonAdd.setAttribute("value", "Add");
document.getElementById("<%=ButtonEdit.ClientID%>").disabled = false;
document.getElementById("<%=ButtonRemove.ClientID%>").disabled = false;
document.getElementById("<%=TextBoxBSISType.ClientID%>").disabled = true;
return false;
}
else {
alert("button now is in add mode");
varButtonAdd.setAttribute("value", "Save");
document.getElementById("<%=ButtonEdit.ClientID%>").disabled = true;
document.getElementById("<%=ButtonRemove.ClientID%>").disabled = true;
document.getElementById("<%=TextBoxBSISType.ClientID%>").disabled = false;
return true;
}
}
</script>
<div style="height: 25px">
</div>
<div style="table-layout: fixed; width: 600px; height: 65px; position: fixed; z-index: auto;">
<fieldset style="width: 382px; height: 47px;">
<legend style="font-weight: bold">BS-IS Types</legend>
<asp:DropDownList ID="DropDownListBSISTypes" AutoPostBack="false" runat="server"
Height="23px" Width="362px">
</asp:DropDownList>
</fieldset>
<asp:Button ID="ButtonAdd" UseSubmitBehavior="true" OnClick="ButtonAddClick" OnClientClick="return !AddClientSide();" Text="Add" runat="server" />
<asp:Button ID="ButtonEdit" runat="server" Text="Button" />
<asp:Button ID="ButtonRemove" runat="server" Text="Remove" />
<div>
<asp:Label ID="LabelBSISType" runat="server" Text="BS-IS Type"></asp:Label>
<asp:TextBox ID="TextBoxBSISType" runat="server" Width="282px"></asp:TextBox>
</div>
</asp:Content>
-
Jun 8th, 2012, 02:52 PM
#2
Frenzied Member
Re: Handling onclick event issue
The only time the client side will execute and not the server side, is if the script returns a false value. Otherwise they will both always execute. I believe.
Justin
-
Jun 8th, 2012, 04:06 PM
#3
Thread Starter
Hyperactive Member
Re: Handling onclick event issue
-
Jun 11th, 2012, 12:56 PM
#4
Thread Starter
Hyperactive Member
Re: Handling onclick event issue
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
|