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?
Related
Pop-up is created as given in image.
In given image ListView is used. In each row last dropdown depends on the second dropdown, and the second depends on the first. Entire dropdown hierarchy is kept in one Update panel for each row. If I select first dropdown I am able to change second.
Dropdowns in layout template and insert template are kept in Update panel and it's working properly, but if I keep dropdowns in item template in Update panel I am getting 500 error.
Tried code is as follows-
<ItemTemplate>
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" />
</td>
<td>
<asp:Image ID="UserRoleImage" runat="server" />
</td>
<td>
--CheckBox Code--
</td>
<td>
--CheckBox Code--
</td>
<td>
--CheckBox Code--
</td>
<asp:updatepanel id="Updatepanel1" runat="server" updatemode="Conditional">
<ContentTemplate>
<td style="width:10%">
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</td>
<td style="width:10%">
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</td>
<td style="width:10%">
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
</td>
</ContentTemplate>
</asp:updatepanel>
<td>
<asp:ImageButton ID="DeleteButton" runat="server" CommandName="Delete" />
</td>
<td></td>
</tr>
</ItemTemplate>
If I remove Update panel it works fine but on dropdown change my pop-up is getting closed. I want to update only one row of listview of pop-up.
Exact same design is added in layout template and insert template.
Got the cause of crash. Since same id of Update panel was using in Item template and Alternate template. I removed Alternate template from list view and Table is rendering perfectly how I was looking for.
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.
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.
I am trying to see the validation part working. I have few required field validators and compare field validators, etc.
<div>
<asp:RequiredFieldValidator ID="rfvCompany" ValidationGroup="groupProfile"
ControlToValidate="txtCompany" runat="server"
ErrorMessage="- Company Name Required" Display="Dynamic" />
</div>
<div>
<asp:RequiredFieldValidator ID="rfvAddress" ValidationGroup="groupProfile"
ControlToValidate="txtAddress" runat="server"
ErrorMessage="- Address 1 Required" Display="Dynamic" />
</div>
This is my save button, validation has to happen when this button is clicked.
<tr>
<td align="center">
<asp:ImageButton ID="btnSave" runat="server" ImageUrl="~/images/green-save.gif"
OnClick="btnSave_Click" TabIndex="22" ValidationGroup="groupProfile" />
</td>
</tr>
The popup that comes when the save button is clicked is this..
<tr>
<td colspan="2" align="left" style="padding-left: 75px; padding-top: 10px;">
Do you wish to update the Location Information as well.
</td>
</tr>
<tr>
<td align="center" colspan="4">
<asp:Button ID="btnYesMerchant" Text ="Yes" runat="server" class="popupButton"
causesvalidation="true" OnClientClick="$find('mdlpop').hide(); return true;"
onclick="btnYessave_Click"/>
<asp:Button ID = "btnNoMerchant" Text ="No" runat ="server" class="popupButton"
causesvalidation="true" OnClientClick="$find('mdlpop').hide(); return true;"
onclick="btnNosave_Click"/>
<asp:Button Id="btnCancel" Text ="Cancel" runat="server" class="popupButton" />
</td>
</tr>
Where am i doing wrong? i am in a serious mess, i guess :(
Ensure you have included the asp:ScriptManager on your page. In addition to that check for javascript errors and (if any) add them to your question.
Here i have assigned the popup to the button, so the popup is being called when the button is clicked. Now i have changed the flow. For the button, i have written a javascript function that will validate and calls the popup to show if validation is passed. This worked. Thank you all..
I have a drop-down list which gathers data from the database and a textbox which contains the text from the drop-down list when I select a value from the drop-down list. I tried to make this work, but no data appears in the textbox when I select a value from the drop-down list and no errors appear either. Can anyone help me?
aspx Code:
<table id="Tbl" runat="server" width="70%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td>
Select
</td>
<td>
<asp:SqlDataSource ID="SDSOption" runat="server" ConnectionString="Data Source=ELARABY-1EACFA3\SQLEXPRESS;Initial Catalog=ElarabyGroup;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [Id], [option] FROM [Option]">
</asp:SqlDataSource>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SDSOption" DataTextField="option"
DataValueField="Id" ondatabound="DropDownList1_DataBound"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
<td>
<b style="font-style: italic">Select Option</b> <b style="font-style: italic">
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TxtOption"
Display="Dynamic" ErrorMessage="*" SetFocusOnError="True"><b style="font-style: italic">*</b></asp:RequiredFieldValidator>
</b>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="LblOption" runat="server" Text="Option"></asp:Label>
</td>
<td class="style1">
<asp:TextBox ID="TxtOption" runat="server"></asp:TextBox>
</td>
<td>
<b style="font-style: italic">Note:Add Here Product Option</b> <b style="font-style: italic">
<br />
<asp:RequiredFieldValidator ID="RVOption" runat="server" ControlToValidate="TxtOption"
Display="Dynamic" ErrorMessage="*" SetFocusOnError="True"><b style="font-style: italic">*</b></asp:RequiredFieldValidator>
</b>
</td>
</tr>
<tr style="font-style: italic">
<td class="style2">
</td>
<td>
<asp:Button ID="BtnSubmit" runat="server" Height="20px" Text="Submit" Width="50px"
OnClick="BtnSubmit_Click" />
</td>
<td align="left">
<b><i><span><a href="EditOption.aspx">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Backend/Image/www_4photos_net_1137678404.jpg"
Width="60px" /></a> Display Other </span></i></b>
</td>
</tr>
</table>
CS Code:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TxtOption.Text += DropDownList1.SelectedItem.Value;
}
The DropDownList is wrapped in an UpdatePanel, but the TextBox is not.
What this means is during the asychronous postback (triggered on the SelectedIndexChanged event), the postback only has visiblity of the controls inside the UpdatePanel (as this is all that gets submitted to the server).
Because the TextBox is outside the UpdatePanel, it does not have visibility of it during the async postback.
The easiest solution would be to put the Textbox inside the UpdatePanel.
Another solution would be to use ScriptManager.RegisterStartupScript to set the value of the control from the SelectedIndexChanged event using basic JavaScript (which has access to the entire DOM, unlike the asynchronous postback).
E.g
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(UpdatePanel1,
this.GetType(),
"NameOfScript",
string.Format("document.getElementById('{0}').value = '{1}';",
txtOption.ClientId,
DropDownList1.SelectedValue));
}