Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i want to create dynamically textboxes and other controls.
I have now the site with a dynamic created textbox and under this a button. If this textboxfield is empty (textbox.text == "") then the button has to been disabled. If the user is writing something in the textbox it has to be enabled.
It works but only after it lost the focus. So now you can write in the textbox, but the button is still disabled while you are in the textbox. I want if you write for example a in the textbox that the button is enabled, and if i delete a without leaving the textbox, that the button is disabled again.

Hope someone can help. I am new in asp.net.
Posted

1 solution

when you are adding the textbox control, add html attribute of onclick.

C#
txtbxHowMany.Attributes.Add("onclick", "ValidateButton(this.id);");


Now, just write a JavaScript function with this name and write ou code of disabling button, let me know if more help needed>
 
Share this answer
 
Comments
alex_78 8-Apr-14 5:04am    
I have this file RetrievalMask.aspx which is the site with the button. It is the search Button which is disabled.



<pre lang="xml"><%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="RetrievalMask.aspx.cs" Inherits="Retrieval.RetrievalMask" %>

<%@ Register assembly="DevExpress.Web.v13.2, Version=13.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<title></title>

<script type="text/javascript">
function ValidateButton()
{

}
</script>


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="dropDown">
<asp:DropDownList runat="server" ID="dropDown" ItemType="Retrieval.RetrievalMask" SelectMethod="FillDropDown" Width="400px" OnSelectedIndexChanged="dropDown_SelectedIndexChanged" AutoPostBack="true" >
</asp:DropDownList>
</div>
<br />
<asp:Panel id="searchMask" runat="server"></asp:Panel>
<br />
<div>
<asp:Button ID="cancel" runat="server" Text="cancel" Visible="false"/>
<asp:Button ID="search" runat="server" Text="search" OnClick="search_Click"/>
</div>
<br />
<div>
<span id="message" runat="server" visible="false">No documents found</span>
</div>
</asp:Content></pre>

--------------------------------------------------
here is the class where i create the textbox. It is in the function SetSearchFieldProperties()


private void SetSearchFieldProperties(ref Control c, RetrievalFieldClass rf)
{
try
{
if (c is TextBox)
{
((TextBox)c).Attributes.Add("runat", "server");
((TextBox)c).Width = 155;
((TextBox)c).TextChanged += new EventHandler(textBox_TextChanged);
((TextBox)c).AutoPostBack = true; // ????
((TextBox)c).Attributes.Add("onclick", "ValidateButton(this.id);");
}
else
{
if (c is DropDownList)
{
((DropDownList)c).Width = 160;
((DropDownList)c).SelectedIndexChanged += new EventHandler(dropDownLookUp_SelectedIndexChanged);
//((DropDownList)c).AutoPostBack = true;
((DropDownList)c).Items.Clear();

((DropDownList)c).Items.Add("");
foreach (string str in rf._lookUpList.Values) //set the lookup longname values in the DropDownList
((DropDownList)c).Items.Add(str);
}
Er. Puneet Goel 8-Apr-14 5:57am    
so whats the issue now?
alex_78 8-Apr-14 9:17am    
i just still have the problem with the parameter in the javascript. I don't know how to declare the function.
Er. Puneet Goel 8-Apr-14 9:23am    
By Adding '((TextBox)c).Attributes.Add("onclick", "ValidateButton(this.id);");'
you have added the onclick event to the textbox.

Also, in function change:
function ValidateButton(objID)
{
//here write your code of enabling or disabling
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900