Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a button in master page and a Free Text box in my content page,now i want to enable the button when i am entering data in Free Text box and disable when there no data in Free Text box

Plz Help me...its urgent
Thanks
Posted
Updated 7-Aug-14 0:43am
v2

you can use text change event of textbox or text box lost focus event to find out master page's conrol.

So you should use got focus event in asp.net ...
 
Share this answer
 
v2
Comments
Member 10924493 7-Aug-14 7:43am    
its not for textchanged,when i clicks in text box then button should be enabled,like keypress event in windows forms but im using asp.net web forms
Try following demo, it may be helpful.
HTML
<input type="text" id="uxSearchText" onkeyup="changeState();"><input type="button" id="uxSearchButton" value="Search" disabled=disabled />
<script type="text/javascript">
    function changeState() {
        var val = document.getElementById('uxSearchText').value;
        if(val.length>0) {
            document.getElementById('uxSearchButton').disabled='';
        }
        else {
            document.getElementById('uxSearchButton').disabled='disabled';
        }
    }
</script>

Let me know if its not working.
 
Share this answer
 
Comments
Member 10924493 8-Aug-14 0:26am    
Hi My button is in Master Page and TextBox is in Content Page,I think we can not use this method,plz give me another thank you
ersandmr 6-Apr-19 19:37pm    
it's work.. thxs so much
There is another way also. Suppose you have Master page as Master.master and child page as Default.aspx. Do following changes in these pages step by step.
In Design of Master page you may have a button as below.
<asp:Button ID="uxSearchButton" runat="server" Text="Search" />

Add new public property in code behind file of Master page as below.
C#
public Button SearchButton
{
    get
    {
        return this.uxSearchButton;
    }
}

In Design part of Default.aspx add MasterType as below.
<%@ MasterType VirtualPath="~/Master.Master" %>

You may have TextBox and script in Design part of Default.aspx as below.
XML
<asp:TextBox ID="uxSearchText" runat="server"></asp:TextBox>
    <script type="text/javascript">
        function changeState(uxSearchText, uxSearchButton) {
            var val = document.getElementById(uxSearchText).value;
            if (val.length > 0) {
                document.getElementById(uxSearchButton).disabled = '';
            }
            else {
                document.getElementById(uxSearchButton).disabled = 'disabled';
            }
        }
    </script>

Add following lines in Page_Load event of Default.aspx page
C#
Master.SearchButton.Attributes.Add("disabled", "disabled");
uxSearchText.Attributes.Add("onkeyup", string.Format("changeState('{0}', '{1}');", uxSearchText.ClientID, Master.SearchButton.ClientID));

Now run the page you will get the result as expected.
 
Share this answer
 
v2
Comments
Member 10924493 9-Aug-14 1:12am    
hi i am not getting the Master page in my Content page i.e Default.aspx. in my Page_load event
like you said Master.SearchButton.Attributes.Add("disabled", "disabled");
I think you missed following tag in Deafault.aspx
ASP.NET
<%@ MasterType VirtualPath="~/Master.Master" %>

Here is complete code of Default.aspx design page.
ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HostDevServer.Default" %>

<%@ MasterType VirtualPath="~/Master.Master" %>
<asp:content id="Content1" contentplaceholderid="head" runat="server" xmlns:asp="#unknown">
</asp:content>
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="server" xmlns:asp="#unknown">
    <asp:textbox id="uxSearchText" runat="server"></asp:textbox>
    <script type="text/javascript">
        function changeState(uxSearchText, uxSearchButton) {
            var val = document.getElementById(uxSearchText).value;
            if (val.length > 0) {
                document.getElementById(uxSearchButton).disabled = '';
            }
            else {
                document.getElementById(uxSearchButton).disabled = 'disabled';
            }
        }
    </script>
</asp:content>

Code behind will be.
C#
protected void Page_Load(object sender, EventArgs e)
        {
            Master.SearchButton.Attributes.Add("disabled", "disabled");
            uxSearchText.Attributes.Add("onkeyup", string.Format("changeState('{0}', '{1}');", uxSearchText.ClientID, Master.SearchButton.ClientID));
        }

I, hope it will work.
 
Share this answer
 
v2

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