Dear all,
I get problem with this ASP.Net form.
As you can see in the sources, I have Check Box (ChkAllCustomer), Combo Box (CmbDept) and Command Button (CmdLocateCustomer).
And to avoid postback I use JavaScript event instead of Anthem.Net.

Everytime user clicks ChkAllCustomer.Checked = true, CmdLocateCustomer enable property is set to false and CmbDept enable property is set to true.
In the other way, if ChkAllCustomer.Checked = false, CmdLocateCustomer enable property is set to true and CmbDept enable property is set to false.

Problem occurs when user clicks CmdLocateCustomer, but somehow CmdDept enable property is set to true manually where as there is not code in CmdLocateCustomer click event.

Please help me.

Thanks and regards,

Kusno.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="RptLoan.aspx.vb" Inherits="RptLoan" EnableSessionState="True"%>
<%@ OutputCache Location="Client" duration="5" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Loan</title> 
    <script language="Javascript" type="text/javascript">
        function ChkAllCustomerClick()
        { 
           if(form1.ChkAllCustomer.checked == true)
           {
              form1.TxtCustomerId.value = "";
              form1.TxtCustomerName.value = "";
              form1.CmdLocateCustomer.disabled = true;
              form1.CmbDept.disabled = false;
           }
           else
           {         
              form1.CmdLocateCustomer.disabled = false;
              form1.CmbDept.disabled = true;
           }
        }
    </script>
</head>
<body bgcolor="#ccccff">
    <form id="form1" runat="server">
        <table style="width: 572px; height: 80px;">
            <tr>
                <td style="width: 94px">
                </td>
                <td><asp:CheckBox ID="ChkAllCustomer" runat="server" Text="All Customer" Width="117px" Checked="True"  onclick="ChkAllCustomerClick()" /></td>
            </tr>
            <tr>
                <td style="width: 94px">
                    Customer :</td>
                <td>
                    <input id="TxtCustomerId" runat="server" readonly="readonly" style="width: 63px" type="text" />&nbsp;<asp:Button
                        ID="CmdLocateCustomer" runat="server" Text="..." Width="25px" Enabled="False" />
                    <input id="TxtCustomerName" runat="server" readonly="readonly" style="width: 246px" type="text" /></td>
            </tr>
            <tr>
                <td style="width: 94px">
                    Department :
                </td>
                <td>
                    <asp:DropDownList ID="CmbDept" runat="server" Width="95px"></asp:DropDownList></td>
            </tr>
        </table>        
    </form>
</body>

Partial Class RptLoan
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            LoadDepartment()
        End If
    End Sub

    Sub LoadDepartment()
        CmbDept.Items.Clear()
        CmbDept.Items.Add("--ALL--")
        CmbDept.Items.Add("BD1")
        CmbDept.Items.Add("BD2")
        CmbDept.Items.Add("BD3")
        CmbDept.SelectedIndex = 0
    End Sub

    Protected Sub CmdLocateCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdLocateCustomer.Click

    End Sub
End Class

Edited 3 Years Ago by mike_2000_17: Fixed formatting

try to explain a litter further on what needs to be done. It was a bit confusing.. or if you could provide a link?

Also, in your javascript, you're not declaring where the form sits. Set a var = document.forms.form1 and then call it everytime you need it. So this means change your javascript code to:

<script language="Javascript" type="text/javascript">
function ChkAllCustomerClick()
{ 
var identity = document.forms.form1;
if(identity.ChkAllCustomer.checked == true)
{
identity.TxtCustomerId.value = "";
identity.TxtCustomerName.value = "";
identity.CmdLocateCustomer.disabled = true;
identity.CmbDept.disabled = false;
}
else
{ 
identity.CmdLocateCustomer.disabled = false;
identity.CmbDept.disabled = true;
}
}
</script>

As for the rest of your code, keep in mind that when it is rendered on page, the ID for that code is different then you chose for it to runat server. View Source on your browser after running the code. Try not to use runat server controls if you don't have to. HTML controls are faster and obviously don't use server resources. So for your cmdLocate button or whatever, make that an HTML button and disabled="disabled" value. This should solve your problem.

CmdLocateCustomer is used to open popup window and send value to it parent page.

In ASP.Net :

 Protected Sub CmdLocateCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdLocateCustomer.Click
        Dim S As String = PopUpWindow("w_customer", "../../Browse/LocateCustomerMaster.aspx?CustomerId=form1.TxtCustomerId&CustomerName=form1.TxtCustomerName", 880, 550)
        If ClientScript.IsClientScriptBlockRegistered("w") = False Then
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "w", S)
        End If
    End Sub

In Javascript :

function CmdLocateCustomer_onclick() {
var w = window.open('"../../Browse/LocateCustomerMaster.aspx?CustomerId=form1.TxtCustomerId&CustomerName=form1.TxtCustomerName','window');
w.focus();
}

I can use one of both scripts. But at least, I want to know why that problem occours when I use ASP.Net control :icon_confused: .

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.