I added a couple of fields manually in my ASPX page which is actually holding a FormView. By manually, I mean by directly typing code in the Markup editor.
Now when I'm trying to access those controls in the code behind, nothing comes up in intellisense.
I deleted the designer.cs file and right clicked the ASPX page and chose Convert to web application, still no go.
The designer file's got the FormView control defined alright, but nothing about its child controls.
Do I really need to use FindControl to get this working ? Tell me if you need some code posted because at the moment maybe I'm just a bit confused about ASP.NET is actually working (or not at this moment).
Here's the markup code:
<%# Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="True" CodeBehind="WebForm_PatientForm.aspx.cs" Inherits="WebAppWalkthrough.WebForm_PatientForm" Title="Employee form" %>
<%# MasterType VirtualPath="~/Site.Master" %>
<asp:Content ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<asp:FormView ID="PatientForm" runat="server" DefaultMode="Edit">
<EditItemTemplate>
<table>
<tr>
<td class="FormViewHeader">
Patient Name:
</td>
<td>
<asp:TextBox ID="PatientName" ReadOnly="true" runat="server" Text='<%# Bind("FullName") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="FormViewHeader">
Patient ID:
</td>
<td>
<asp:TextBox ID="PatientID" ReadOnly="true" runat="server" Text='<%# Bind("patientid") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="FormViewHeader">
Eligibility
</td>
<td>
<asp:DropDownList runat="server" ID="Eligibility" SelectedValue='<%# Bind("service_executive_eligibility") %>' >
<asp:ListItem Value="" Text="N/A" />
<asp:ListItem Value="True" Text="Yes" />
<asp:ListItem Value="False" Text="No" />
</asp:DropDownList>
</td>
</tr>
</table>
<asp:LinkButton ID="LinkButton2" runat="server" OnCommand="UpdatePatientInfo" Text="UpdateInfo" CommandArgument='<%# Bind("patientid") %>'>Update</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" OnCommand="CancelEditPatient" CommandName="CancelUpdate" Text="CancelInfo">Cancel</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
<table>
<tr>
<td class="FormViewHeader">
Employee First Name:
</td>
<td>
<asp:TextBox ID="FirstName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="FormViewHeader">
Employee Last Name:
</td>
<td>
<asp:TextBox ID="LastName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="FormViewHeader">
Email address:
</td>
<td>
<asp:TextBox ID="EmailAddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="FormViewHeader">
Work phone number:
</td>
<td>
<asp:TextBox ID="PhoneNumber" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="FormViewHeader">
Eligibility
</td>
<td>
<asp:DropDownList runat="server" ID="Eligibility">
<asp:ListItem Value="True" Text="Yes" />
<asp:ListItem Value="False" Text="No" />
</asp:DropDownList>
</td>
</tr>
</table>
<asp:LinkButton ID="LinkButton5" runat="server" OnCommand="AddEmployee" Text="Add Employee">Add</asp:LinkButton>
</InsertItemTemplate>
</asp:FormView>
</asp:Content>
Even if I add the controls manually in the designer file, I get a null reference error in the code behind at run time (even if intelisense picks up FirstName the object is null at runtime).
EDIT: I will try installing VS2010 SP1 and this hotfix I found and post the results.
EDIT 2: So I installed VS2010 SP1 which didn't solve the issue. I could not install the hotfix as my system is x64.
So I ditched VS2010 and tried with VS2013, which still doesn't pickup the markup controls.
Even Page.FindControl("ControlName") returns null. Something is very rotten with that webpage or VS2013...
Thanks.
I encountered a problem that seems similar with Telerik UI components for WebForms before. I wanted to access items that were defined inside of a template in a grid, but unfortunately the only way to do that was to dig into child elements of that grid. That inner elements were not present in the designer.cs file as well.
I am not sure about that, but it can be a common behavior of nested elements in WebForms.
Related
Why can't I use the (input) I put in my (list view) in the C # code field?
<asp:ListView ID="ListV" runat="server">
<ItemTemplate runat="server">
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<tr class="text-center">
<td class="product-remove"></td>
<td class="image-prod">
<div class="">
<asp:Image ID="Image1" CssClass=" img" ImageUrl='<%# "../img/" + Eval("picture")
%> ' runat="server" />
</div>
</td>
<td class="product-name"><%# Eval("namebook") %> </td>
<td class="price"><%# Eval("Price") %> </td>
<td class="quantity"><%# Eval("titel") %></td>
<td class="col-2">
<asp:Button ID="delete" CssClass="btn btn-outline-danger" CommandArgument='<%#
Eval("id")%>' OnClick="delete_Click" runat="server" Text="حذف کالا" />
</td>
<td>
<input id="quantity2" runat="server" type="number" value="1" min="1" max="20" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
You want a server control there. Additionally, this control only exists as part of an item template, meaning there isn't just one control named quantity2... there could be many, depending on the data source. Therefore referencing it just by name is not good enough. And speaking of data sources, depending on how you handle this the databinding may not have taken place yet at the time the Page_Load code runs, meaning the input control doesn't exist at all.
So the real question is: what do you want to do with this input?
CodeBehind="~/ (Page Name) .aspx.cs"
i have an user control in that i used cascading drop down for states,districts and areas...how to load cascading drop down in user control page load....cascading Drop down code is
<table>
<tr>
<td class="caption">
State:
<asp:DropDownList ID="ddlCState" runat="server" CssClass="userentry">
</asp:DropDownList>
<cc1:CascadingDropDown ID="cdlCStates" TargetControlID="ddlCState" PromptText="Select State"
ServicePath="~/CasCadingDropDown.asmx" ServiceMethod="GetStates" runat="server"
Category="StateId" LoadingText="Loading..." />
</td>
</tr>
<tr>
<td class="caption">
District:
<asp:DropDownList ID="ddlCDistrict" runat="server" CssClass="userentry">
</asp:DropDownList>
<cc1:CascadingDropDown ID="cdlCDistrict" TargetControlID="ddlCDistrict" PromptText="Select District"
ServicePath="~/CasCadingDropDown.asmx" ServiceMethod="GetDistricts" runat="server"
Category="DistrictId" ParentControlID="ddlCState" LoadingText="Loading..." />
</td>
</tr>
<tr>
<td class="caption">
Area:
<asp:DropDownList ID="ddlCArea" runat="server" CssClass="userentry">
</asp:DropDownList>
<cc1:CascadingDropDown ID="cdlCAreas" TargetControlID="ddlCArea" PromptText="Select Area"
ServicePath="~/CasCadingDropDown.asmx" ServiceMethod="GetAreas" runat="server"
Category="AreaId" ParentControlID="ddlCDistrict" LoadingText="Loading..." />
</td>
</tr></table>
I have registration form for users to fill up. In there, one field is there to which if user checks on the button a text box shoulld be enabled to enter the number. I have used following code :
<asp:UpdatePanel ID="upMSME" runat="server">
<ContentTemplate>
<tr>
<td colspan="2">
<asp:Label ID="lblMSME" runat="server" Text="Whether covered under MSME (Tick whichever is applicable)"></asp:Label>
<asp:CheckBox AutoPostBack="true" Checked="true" ID="chbMSME" runat="server" OnCheckedChanged="chbMSME_CheckedChanged" ClientIDMode="AutoID"/>
</td>
</tr>
<tr id="trMSMENo" runat="server">
<td>
<asp:Label ID="lblMSMENo" runat="server" Text="MSME Number" CssClass="alignTop"></asp:Label>
</td>
<td class="ValueBox">
<asp:TextBox ID="txtMSMENo" runat="server" MaxLength="75"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvMSMENo" runat="server" ForeColor="Red" ErrorMessage="*" ControlToValidate="txtMSMENo" ValidationGroup="vgVendor"></asp:RequiredFieldValidator>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
However I searched over internet and found that by setting the ClientIDMode="AutoID" the issue is resolved. But in my case after setting the property there is still full postback occurred.
I have another update panel also in this form, does it make any difference?
What am I missing?
Overview: Clicking on text of first CheckBox in a repeater control clicks the last one. I know why this is happening; association of label tag with element id chkMarkedForDeletion and when that label is clicked it selects the last CheckBox, as all the CheckBoxes have same ID.. damn you repeater control!! I am wondering if there is any way to avoid this? Easy way would be to create individual labels and associate correctly to each CheckBox but that defeats the supposed default behaviour of a CheckBox.
Repeater code:
<asp:Repeater ID="childNodesDataRepeater" runat="server">
<ItemTemplate>
<table style="width: 100%;" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="width: 200px;">
<asp:CheckBox ID="chkMarkedForDeletion" runat="server" EnableViewState="true" Text="Remove"
Checked='<%# DataBinder.Eval(Container.DataItem, "IsMarkedForDeletion") %>' />
</td>
<td>
</td>
<td style="width: 200px;">
<asp:CheckBox ID="chkHighImpactCause" runat="server" EnableViewState="true" Text="High Impact Cause"
Checked='<%# DataBinder.Eval(Container.DataItem, "IsHighPriority") %>' />
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="header002" runat="server" Text="What caused this problem?" />
</td>
</tr>
<tr>
<td colspan="3">
<asp:TextBox ID="txtProblemCausedBy" runat="server" EnableViewState="true" Width="100%"
Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>' /><br />
</td>
</tr>
<tr>
<td colspan="3" style="height: 5px;">
<hr />
<asp:HiddenField ID="nodeIdentifier" runat="server" EnableViewState="true" Value='<%# DataBinder.Eval(Container.DataItem, "AnalysisID") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
Generated HTML Code for CheckBox:
<INPUT id=chkMarkedForDeletion type=checkbox name=TabContainer$tabProblemResolution$frmProblemResolution1$childNodesDataRepeater$ctl00$chkMarkedForDeletion>
<LABEL for=chkMarkedForDeletion>Remove</LABEL>
...
...
<INPUT id=chkMarkedForDeletion type=checkbox name=TabContainer$tabProblemResolution$frmProblemResolution1$childNodesDataRepeater$ctl02$chkMarkedForDeletion>
<LABEL for=chkMarkedForDeletion>Remove</LABEL>
Issue:
Thanks,
Abhi
Make sure the ClientIDMode on the repeater is not set to "Static".
This setting is inheritable from the parent, which goes all the way up to web.config. So if you have to set the ClientIDMode explicitly on the repeater, it means that some parent overrides the default (Predictable) to "Static".
I am using dropdownlist placed inside ajax tab container.but it doesnt postback even though i have set autopostback property to true.This happens only in firefox and not in IE or chrome.Can any body help me regarding this.I am using ajax toolkit version 4.1.50731.0.
<asp:TabContainer ID="TabContainer2" runat="server" Width="100%" CssClass="myTab"
Height="2200px" ActiveTabIndex="0">
<asp:TabPanel ID="TabPanel8" runat="server" HeaderText="Add Transaction">
<ContentTemplate>
<div>
<table class="style1">
<tr>
<td class="style16">
</td>
<td align="right" class="style15">
Select News Heading :
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True" >
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ControlToValidate="DropDownList1"
ErrorMessage="Please Select News Heading" ValidationGroup="a" InitialValue="Select News Heading">*</asp:RequiredFieldValidator><asp:ValidatorCalloutExtender
ID="RequiredFieldValidator12_ValidatorCalloutExtender" runat="server" Enabled="True"
TargetControlID="RequiredFieldValidator12">
</asp:ValidatorCalloutExtender>
<asp:Label ID="Label3" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td class="style16">
</td>
<td align="right" class="style15">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style16">
</td>
<td align="right" class="style15">
Select Sub Heading :
</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" OnLoad="DropDownList2_Load">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server" ControlToValidate="DropDownList2"
ErrorMessage="Please select sub heading" ValidationGroup="a" InitialValue="Select News Name">*</asp:RequiredFieldValidator><asp:ValidatorCalloutExtender
ID="RequiredFieldValidator14_ValidatorCalloutExtender" runat="server" Enabled="True"
TargetControlID="RequiredFieldValidator14">
</asp:ValidatorCalloutExtender>
<asp:Label ID="Label4" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
you do appear to be missing a closing </table> and </div> tag from your content template.
does adding those fix your problem?
edit
Does your javascript console (e.g. firebug in firefox) give you any javascript errors?
Solution to your problem that I assume is:
If validation is failing then DropDownList won't PostBack, so please try once by disabling the Validators on DropDownList.
Some points to note
RequiredFieldValidator should have Display="None" as you are using ValidatorCalloutExtender
Put CausesValidation on the DropDownList and RequiredFieldValidator
It would result in auto triggering the validation on server-side.
Check the Page.IsValid in the SelectedIndexChanged event handler before proceeding any other code parts.