Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 10, 2009 08:09 AM by jaiswarvipin
Member
575 Points
205 Posts
Apr 09, 2009 12:18 PM|LINK
hi
i am having one datalist and that datalist has textbox controls like this
asp
how can i dosable the textbox control at runtime in code behind
how can i use the css to disable the control ?
All-Star
112168 Points
18255 Posts
Moderator
Apr 09, 2009 12:38 PM|LINK
Uh, doesn't test.Enabled = false; work?
82577 Points
15430 Posts
MVP
Apr 09, 2009 12:50 PM|LINK
Remember that if you disable a TextBox server-side, you cannot change the value client-side and have the new value persist to the server-side.
NC...
Apr 09, 2009 01:55 PM|LINK
can u please explain
Apr 09, 2009 01:57 PM|LINK
no it's not working
because when i send the page for processing it does not find the datalist control so i am not able to disable the control
if datalist is found and control also this enabled=false statement is not working for me
that's why i am looking for some css type of solution
Apr 09, 2009 02:18 PM|LINK
A DataList renders as an HTML table tag. CSS cannot disable a control. It only works on the display.
Here is an example of what you can do.
aspx file:
<asp:datalist id="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound"> <itemtemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button id="Button1" runat="server" text="Disable TextBox" OnClick="Button1_Click"></asp:Button> </itemtemplate> </asp:datalist>
<script type="text/javascript"> <!-- function disableTextBox(textBoxId) { var textBoxRef = document.getElementById(textBoxId); textBoxRef.disabled = (textBoxRef.disabled == true) ? false : true; } // --> </script>
aspx.cs file:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { if ((e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item)) { TextBox textBoxRef = (TextBox)e.Item.FindControl("TextBox1");
// Uncomment to disable server-side... //if ( textBoxRef != null ) //{ // textBoxRef.Enabled = false; //}
// Uncomment to disable client-side on the click of the Button... //Button buttonRef = (Button)e.Item.FindControl("Button1"); //if ( (textBoxRef != null) && (buttonRef != null) ) //{ // string clickHandler = string.Format("disableTextBox('{0}'); return false;", textBoxRef.ClientID); // buttonRef.Attributes.Add("onclick", clickHandler); //} } }
Apr 09, 2009 02:32 PM|LINK
i am senind page some other file for disable and enable
i have around 100 pages
think in this way
i have page then controls and one of the control is datalist having textbox with ajaxautocomplete
Participant
808 Points
159 Posts
Apr 09, 2009 02:50 PM|LINK
Via CSS. you can do this way
<asp:TextBox .......... Style="Css Class Name" OnKeyUp="this.ClassName=CssClassNameWhoEnabledTheTesxBox"></asp:TextBox >
Like this using Event of object we can assign the the "this.ClassName =[Class Name]".
If Not Calear then Please publis your code (.aspx and CSS) such that i will help you out.
Apr 09, 2009 03:46 PM|LINK
jaiswarvipin Via CSS. you can do this way <asp:TextBox .......... Style="Css Class Name" OnKeyUp="this.ClassName=CssClassNameWhoEnabledTheTesxBox"></asp:TextBox > Like this using Event of object we can assign the the "this.ClassName =[Class Name]". If Not Calear then Please publis your code (.aspx and CSS) such that i will help you out.
Post this CSS class that will disable a TextBox, or any control for that matter (besides making the control disappear).
Contributor
5103 Points
851 Posts
Apr 09, 2009 03:47 PM|LINK
ajaypathak how can i dosable the textbox control at runtime in code behind
In code behind,
txtbxId.Enabled=false; //will disable your control but it can not be used if the control is inside repeater/datalist
For that purpose, NC's solution seems best for me.
ajaypathak how can i use the css to disable the control ?
No way to do that only using CSS. You need to use Javascript as many of us have suggested.
Thanks.
ajaypathak
Member
575 Points
205 Posts
disable textbox control in code behind via css file
Apr 09, 2009 12:18 PM|LINK
hi
i am having one datalist and that datalist has textbox controls like this
asp
:TextBox ID="test" onkeyup="enable(this);" onkeydown="if(event.keyCode == 13) return false;" onmouseover="showContents(this, 10);" runat="server" Style="display: inline"></asp:TextBox> <ajaxToolkit:AutoCompleteExtender ID="ClassCodeLookUpExt" runat="server" BehaviorID="AutoCompleteEx" TargetControlID="class_code" ServiceMethod="ClassCodesList" MinimumPrefixLength="1" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="12" CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" DelimiterCharacters="" FirstRowSelected="true" UseContextKey="true" ContextKey="param" OnClientItemSelected="updateClassCodeQuestions">how can i dosable the textbox control at runtime in code behind
how can i use the css to disable the control ?
MVP
All About ASP.net
MetalAsp.Net
All-Star
112168 Points
18255 Posts
Moderator
Re: disable textbox control in code behind via css file
Apr 09, 2009 12:38 PM|LINK
Uh, doesn't test.Enabled = false; work?
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: disable textbox control in code behind via css file
Apr 09, 2009 12:50 PM|LINK
Remember that if you disable a TextBox server-side, you cannot change the value client-side and have the new value persist to the server-side.
NC...
ajaypathak
Member
575 Points
205 Posts
Re: disable textbox control in code behind via css file
Apr 09, 2009 01:55 PM|LINK
can u please explain
MVP
All About ASP.net
ajaypathak
Member
575 Points
205 Posts
Re: disable textbox control in code behind via css file
Apr 09, 2009 01:57 PM|LINK
no it's not working
because when i send the page for processing it does not find the datalist control so i am not able to disable the control
if datalist is found and control also this enabled=false statement is not working for me
that's why i am looking for some css type of solution
MVP
All About ASP.net
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: disable textbox control in code behind via css file
Apr 09, 2009 02:18 PM|LINK
A DataList renders as an HTML table tag. CSS cannot disable a control. It only works on the display.
Here is an example of what you can do.
aspx file:
<asp:datalist id="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
<itemtemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server" text="Disable TextBox" OnClick="Button1_Click"></asp:Button>
</itemtemplate>
</asp:datalist>
<script type="text/javascript">
<!--
function disableTextBox(textBoxId)
{
var textBoxRef = document.getElementById(textBoxId);
textBoxRef.disabled = (textBoxRef.disabled == true) ? false : true;
}
// -->
</script>
aspx.cs file:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item))
{
TextBox textBoxRef = (TextBox)e.Item.FindControl("TextBox1");
// Uncomment to disable server-side...
//if ( textBoxRef != null )
//{
// textBoxRef.Enabled = false;
//}
// Uncomment to disable client-side on the click of the Button...
//Button buttonRef = (Button)e.Item.FindControl("Button1");
//if ( (textBoxRef != null) && (buttonRef != null) )
//{
// string clickHandler = string.Format("disableTextBox('{0}'); return false;", textBoxRef.ClientID);
// buttonRef.Attributes.Add("onclick", clickHandler);
//}
}
}
NC...
ajaypathak
Member
575 Points
205 Posts
Re: disable textbox control in code behind via css file
Apr 09, 2009 02:32 PM|LINK
i am senind page some other file for disable and enable
i have around 100 pages
think in this way
i have page then controls and one of the control is datalist having textbox with ajaxautocomplete
MVP
All About ASP.net
jaiswarvipin
Participant
808 Points
159 Posts
Re: disable textbox control in code behind via css file
Apr 09, 2009 02:50 PM|LINK
Via CSS. you can do this way
<asp:TextBox .......... Style="Css Class Name" OnKeyUp="this.ClassName=CssClassNameWhoEnabledTheTesxBox"></asp:TextBox >
Like this using Event of object we can assign the the "this.ClassName =[Class Name]".
If Not Calear then Please publis your code (.aspx and CSS) such that i will help you out.
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: disable textbox control in code behind via css file
Apr 09, 2009 03:46 PM|LINK
Post this CSS class that will disable a TextBox, or any control for that matter (besides making the control disappear).
NC...
NHOQUE
Contributor
5103 Points
851 Posts
Re: disable textbox control in code behind via css file
Apr 09, 2009 03:47 PM|LINK
In code behind,
txtbxId.Enabled=false; //will disable your control but it can not be used if the control is inside repeater/datalist
For that purpose, NC's solution seems best for me.
No way to do that only using CSS. You need to use Javascript as many of us have suggested.
Thanks.
[n°web]