I'm using the following dropdown & mapping its value into a textbox.
<asp:DropDownList ID="ddlCntry" runat="server" Height="24px" Width="160px"
OnChange="Country();">
<asp:ListItem>Select Country</asp:ListItem>
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>USA</asp:ListItem>
<asp:ListItem>UK</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TxtCntryRisk" runat="server"
ontextchanged="TxtCntryRisk_TextChanged" Width="153px"
EnableTheming="True" Enabled="False"></asp:TextBox>
I have a calculation button, when I click on the button my mapped textbox value gets lost.
I want my textbox to be disabled so that its value cannot be changed.
I tried using Readonly=true property also but in vain. Session, viewstate also not working.
but when I enable the textbox, it's working fine, no loss of value.
any help??
thanx in advance. :-)
Set the ReadOnly attribute server side:
TxtCntryRisk.Attributes.Add("readonly","readonly");
Related
I have three textbox and one button. Here is my problem:
I use autopostback="true" in textbox, i entered some value and after first click of the button is not working. Then i click again, second click is working. I looked on F12 developer tool on Browser, there is no an error. When i set autopostback="false" than button click is working without any problem.
I would like to use autopostback="true" because it helps me. I think there is a focus problem because when i click out of textbox and than click on the button, button works with autopostback="true"
Do you have any idea for solution of this problem. All controls are working server-side.
<asp:Textbox ID="Name" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Textbox ID="Surname" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Textbox ID="City" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Button ID="send_btn" runat="server Text="Check and Send" OnClick="send_btn_Click" ValidationGroup="myval"></asp:Button>
I found a solution. It's not stable solution but however it's working. I hope it helps you too. My solution is:
<asp:Button ID="send_btn" runat="server Text="Check and Send" OnClick="send_btn_Click" OnClientClick="return true;" ValidationGroup="myval"></asp:Button>
I added OnClientClick="return true;" and button click is working on first click now.
If you have better solution waiting for your response.
I have an EntityDataSource control that is bind to an edmx file.
I create a detailsview and set it's DataSource property to entitydatasource control.
now I want to put a DropDownList instead of TextBox for "no_region_code" in Inserting mode.
Here is what I found from internet but it does not insert the contents of dropdownlist to the table when i click on insert button of detailsview.
<asp:TemplateField HeaderText="no_region_code" SortExpression="no_region_code">
<InsertItemTemplate>
<asp:DropDownList ID="drp_region_list" runat="server" DataMember="no_region_code">
<asp:ListItem Value="41">tabriz</asp:ListItem>
<asp:ListItem Value="21">tehran</asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
How can I put a dropdownlist instead of these textboxes?
You didn't bind any property on that DropDownList. Try something like this
<asp:DropDownList ID="drp_region_list" runat="server" SelectedValue='<%# Bind("no_region_code")%>' DataMember="no_region_code">
<asp:ListItem Value="41">tabriz</asp:ListItem>
<asp:ListItem Value="21">tehran</asp:ListItem>
</asp:DropDownList>
EDIT : bind represent a way to link your property from the code behind (or model) to an asp control. This binding is bidirectional. For example, if you already have a value for no_region_code property in the code behind, the dropdown will already have that value selected on the view. Google asp.net data binding and you'll find a lot of examples and some more in depth explanations.
I have an ASP Drop Down List that opens then immediately collapses on one click. I'm using a Drop Down on another page with the same CssClass, and it's working fine (first click expands the DDL and the second click collapses it). Anyone have any idea what could be happening? I would greatly appreciate any suggestions or input.
<label>
<asp:RadioButton ID="rbToAccount" runat="server" GroupName="rbTo" />
Account
<asp:DropDownList ID="ddlToAccount" runat="server" CssClass="span4 m-wrap">
</asp:DropDownList>
</label>
Try This :
<label></label>
<asp:RadioButton ID="rbToAccount" runat="server" GroupName="rbTo" />
Account
<asp:DropDownList ID="ddlToAccount" runat="server" CssClass="span4 m-wrap">
</asp:DropDownList>
is the event tied to a Jquery function??
It sounds like on dropdown list change it is causing a postback, which then is refreshing the page to it's original state. Try adding OnClientClick="return false" as an attribute to the ddl control
I have a databound dropdown list on my page. The first value in the selection list is blank. Is there a way that I can change it so that the first selection says "Unassigned" instead of blank? I've tried the following, but it didn't work:
// Insert 'Unassigned' value for artist dropdown
ddlArtists.Items.Insert(0, "Unassigned");
After inserting the above code, the list still appears unchanged, with the first selection value being a blank. Any pointers would be great! Thank you!
EDIT: Here is the code for the dropdown:
<asp:DropDownList ID="ddlArtists" runat="server" Width="130px" TabIndex="5"
OnSelectedIndexChanged="ddlArtists_SelectedIndexChanged"
DataSourceID="sqldsArtist" DataTextField="Name" DataValueField="ID"
OnDataBound="ddl_DataBound"
AutoPostBack="True">
You don't need to do it on the CodeBehind. Just do it like that:
<asp:DropDownList ID="ddlArtists" runat="server" AppendDataBoundItems="true">
<asp:ListItem Text="Unassigned" Value="0" Selected="true" />
</asp:DropDownList>
The AppendDataBoundItems property defines whether the contents of the DropDownList should be cleared out before data binding.
Don't forget to check for a PostBack when you're data binding it, to avoid duplicates.
Set the SelectedIndex property of your DropDownList to 0.
I have divised a page with a TabContainer.
Before, this page worked with a CascadingDropDown that populate a DropDownList.
Now this DropDownList is in another tab. So I catch an exception "Object Reference Null" when I try to see this page.
How did runs to load a DropDownList in another Tab when I change a value in a different Tab ?
Update:
Thanks for your answer, but unfortunaly it doesn't work.
I have tried with CascadingDropDownExtender outside the TabContainer, but Reference null is catched again.
With CascadingDropDownExtender in same Panel as child DropDownList, I have a javascript alert that say Parent Control not found.
Here the code with CascadingDropDownExtender in same Panel as child DropDownList
<cc2:TabPanel runat="server" HeaderText="Carte Identité" ID="TabCI">
<ContentTemplate>
<ProspectMgt:MarketSegmentDropDownList ID="MarketSegmentDropDownList1" runat="server"
AutoPostBack="false" Width="400px"></ProspectMgt:MarketSegmentDropDownList>
<asp:CompareValidator ID="CompareValidator2" runat="server" CssClass="error" ToolTip="Required"
ControlToValidate="MarketSegmentDropDownList1" ValueToCompare="-1" Operator="NotEqual"
ErrorMessage="MktSegment" Display="Dynamic" Font-Bold="True"></asp:CompareValidator>
</ContentTemplate>
</cc2:TabPanel>
<cc2:TabPanel ID="TabSize" runat="server" HeaderText="Size & Volume">
<ContentTemplate>
<asp:DropDownList ID="DropDownListSize" AutoPostBack="false" runat="server">
</asp:DropDownList>
<cc2:CascadingDropDown ID="cddSize" runat="server" TargetControlID="DropDownListSize"
Category="Size" LoadingText="[...]"
ServicePath="~/Modules/ProspectMgt/WebService/ServiceAjax.asmx" ServiceMethod="GetSizeByMktId"
ParentControlID="MarketSegmentDropDownList1" />
</ContentTemplate>
</cc2:TabPanel>
So I don't see why it is not working. It was working perfectly without TabContainer. I'm using AjaxToolKit 30512. However, I'm looking to drop CascadingDropDownExtender and manage this issue by javascript only.
Is the CascadingDropDownExtender inside the first tab? If it is, if you pull the CascadingDropDownExtender outside the tab container altogether, does that fix the issue? Posting some markup would help resolve this more easily...
HTH.