<asp:UpdatePanel > doesn't work inside a table <tr>? - c#

I have a problem getting an <asp:UpdatePanel..> to work inside a <table>.. <tr> </tr> structure and I don't know why. When the UpdatePanel is commented out everything works fine, but when I un-comment the UpdatePanel the contents of the <tr> </tr> tag doesn't even show up in Visual Studio 2010. This content does display when I run the web page but the UpdatePanel doesn't work. Non of my other web pages in this project have this problem but, then again, I use <div>s instead of <table>s in them.
One other thing. The is in my MasterPage.
Here is my script:
<asp:UpdatePanel ID="W9UpdatePanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<tr>
<td colspan="6">
<div class="branchSetupSectionTitle">W-9 Information:</div>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnDownloadW9Pdf" runat="server"
Text="Download W-9" onclick="btnDownloadW9Pdf_Click" AutoPostBack="True" />
<%--<asp:RegularExpressionValidator ID="RegularExpressionValidator24"
runat="server" ControlToValidate="txtFirstPaymentAmount" Display="Dynamic"
ErrorMessage="The dollar amount you entered is in the wrong format."
ForeColor="Red" ValidationExpression="^\d+(\.\d\d)?$">*</asp:RegularExpressionValidator>--%>
<asp:CheckBox ID="chkW9FormSubmitted" runat="server" AutoPostBack="True"
oncheckedchanged="chkW9FormSubmitted_CheckedChanged"
Text=" I have submitted this W-9 Form" />
</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
</tr>
The event fires for both the button and the checkbox but the entire page is refreshed.
Thanks for your help.

UpdatePanel needs to render a div or span in order to function correctly. Since neither of these elements can be rendered between table rows, UpdatePanel does not have a placeholder to render the postback response html, and thus it doesn't work.
A workaround in your case may be to see which part of your page does not need to be inside the update panel and leave it outside. You could leave just the contents of <td colspan="2"> inside the UpdatePanel.

<asp:ScriptManager ID="scm" runat="server">
</asp:ScriptManager>
<fieldset>
<legend>Truck Master Entry Form</legend>
<asp:UpdatePanel ID="upd1" runat="server">
<ContentTemplate>
<table cellpadding="2" cellspacing="1">
<tr>
<td align="right">
Truck no :
</td>
<td align="left">
<asp:TextBox ID="truckno" runat="server" Width="120px" Height="20px" />
</td>
</tr>
<tr>
<td align="right">
Size :
</td>
<td align="left">
<asp:DropDownList ID="drptrucksize" runat="server" Width="120px" Height="20px" DataValueField="WEIGHT"
DataTextField="SIZE" OnSelectedIndexChanged="drptrucksize_SelectedIndexChanged"
AutoPostBack="true" />
</td>
</tr>
<tr>
<td align="right">
Type :
</td>
<td align="left">
<asp:TextBox ID="txttrucktype" runat="server" Width="120px" Height="20px" />
</td>
</tr>
<tr>
<td align="right">
Weight :
</td>
<td align="left">
<asp:TextBox ID="txtweight" runat="server" Width="120px" Height="20px" />
</td>
</tr>
<tr>
<td align="right">
</td>
<td align="left">
<asp:Button ID="btnsave" runat="server" Text="Save" Width="100px" Height="50px" />
<asp:Button ID="btncancel" runat="server" Text="Cancel" Width="100px" Height="50px" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>

The update panel need to be put outside the table. Look at
Mohammad Shahnawaz's code.

Related

Enable to edit after a checkbox

I have a table with some information shown, but I would like to able to edit after I click the checkbox above.
<asp:Button ID="Backbtn" runat="server" Text="Back" Width="84px"
onclick="Backbtn_Click" />
<br /><br />
<asp:CheckBox ID="CheckBox1" runat="server" onclick="check" Text="Check"/>
<table class="T-Table" >
<tr>
<th colspan="6"><em>IT INTERNAL USE</em></th>
</tr>
<tr>
<td width="180px">Doc.No </td>
<td>:</td>
<td width="160px">
<asp:Label ID="DocNo" runat="server" Text="Label"></asp:Label>
</td>
<%-- <td width="180px">Job Complete Date </td>
<td>:</td>
<td width="160px">
</td> --%>
</tr>
<tr>
<td>Received Date :</td>
<td>:</td>
<td>
<asp:Label ID="RDate" runat="server" Text="Label"></asp:Label>
</td>
<td>Response Time (HR) :</td>
<td>:</td>
<td><asp:TextBox ID="Response_T" runat="server" TextMode="DateTimeLocal"></asp:TextBox>
</td>
</tr>
<tr>
<td>Remarks </td>
<td>:</td>
<td colspan="5"><asp:TextBox ID="Remarks" runat="server" Rows="5" TextMode="MultiLine"
Columns="80"></asp:TextBox></td>
</tr>
<tr>
<td>Cost charge to Department </td>
<td>:</td>
<td><asp:TextBox ID="Cost" runat="server" ></asp:TextBox></td>
<td>Status</td>
<td>:</td>
<td> <asp:DropDownList ID="Progress" runat="server">
<asp:ListItem Text="Done" Value="Done"></asp:ListItem>
<asp:ListItem Text="In Progress" Value="In Progress"></asp:ListItem>
<asp:ListItem Text="Pending" Value="Pending"></asp:ListItem>
</asp:DropDownList></td>
</tr>
Here are some html code. I would like to add a function so that all the information can be editable after I click the Checkbox.
Thank you
There is nothing to do with C# or Linq here (as you tagged).
Assuming you are working on an ASP.NET application
Enable the checkbox AutoPostback. ie, Set AutoPostback property of the checkbox to true.
Then on page load or checkbox checked change event, enable the textbox.
eg. name of text editor is txtRemarks and checkbox name to be chkRemarksEditor
on chkRemarksEditor Checked change event :-
txtRemarks.Enabled = chkRemarksEditor.Checked;

Implementing two contact forms with validation controls in a single page in ASP.NET?

I'm using two contact forms in the same aspx page, one has 4 textbox controls (name- email- subject- body) and send button control.
The second form has 2 textbox controls and send button, all (except the second textbox of the second form) has validation controls (requiredFieldValidator).
This is the code inside the first button click event:
protected void ButtonSend_Click(object sender, EventArgs e)
{
if(Page.IsValid)
{
LabelIRespond.Visible = true;
.....
}
}
there is no code in the second button click event.
the problem is, when the first form validated successful and the second form not validated, the code inside click event not executed. and the error message of the second form appears. They act like they are one form!
The markup for both forms:
<section id="sendSection">
<div id="contactMe">
<h1>Contact me</h1>
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<h4>Send me a message:</h4>
<table class="auto-style1">
<tr>
<td class="auto-style8">
<asp:TextBox ID="TextBoxEmail" placeholder="Your Email address" runat="server" BackColor="#D4D8DF" Font-Names="Century Gothic" CssClass="txtbxs" Height="25px" Width="250px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorEmail" runat="server" ControlToValidate="TextBoxEmail" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Please enter your Email address">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBoxEmail" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="RegularExpressionValidator" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style8">
<asp:TextBox ID="TextBoxName" placeholder="Your name" runat="server" BackColor="#D4D8DF" Font-Names="Century Gothic" CssClass="txtbxs" Height="25px" Width="250px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ControlToValidate="TextBoxName" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style5">
<asp:TextBox ID="TextBoxSubject" placeholder="Subject" runat="server" BackColor="#D4D8DF" Font-Names="Century Gothic" CssClass="txtbxs" Height="25px" Width="250px"></asp:TextBox>
</td>
<td class="auto-style3">
<asp:RequiredFieldValidator ID="RequiredFieldValidatorSubject" runat="server" ControlToValidate="TextBoxSubject" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style6">
<asp:TextBox ID="TextBoxBody" placeholder="What do you want to tell me?" runat="server" BackColor="#D4D8DF" TextMode="MultiLine" Font-Names="Century Gothic" CssClass="txtbxs" Height="180px" Width="370px"></asp:TextBox>
</td>
<td class="auto-style2">
<asp:RequiredFieldValidator ID="RequiredFieldValidatorBody" runat="server" ControlToValidate="TextBoxBody" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Type your message">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style8">
<asp:Button ID="ButtonSend" runat="server" Text="Send" CssClass="btnSend" Width="80px" OnClick="ButtonSend_Click" UseSubmitBehavior="False" Font-Names="Century Gothic" />
</td>
<td>
</td>
</tr>
<tr>
<td class="auto-style8">
<asp:Label ID="LabelIRespond" runat="server" Text="Thanks, your message has been sent. I'll respond ASAP." Visible="False"></asp:Label>
</td>
<td>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="wait">
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</section>
<div class="split"></div>
<section id="viewCVSection">
<div id="check">
<h1>Check out my CV</h1>
</div>
<div class="cvForm">
<table class="auto-style1">
<tr>
<td class="auto-style4">
<asp:TextBox ID="TextBoxEmail2" placeholder="Company Email address" CssClass="txtbxs" runat="server" BackColor="#D4D8DF" Height="25px" Width="250px" Font-Names="Century Gothic"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxEmail2" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBoxEmail2" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="RegularExpressionValidator" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style4">
<asp:TextBox ID="TextBoxCompany" placeholder="Company name" CssClass="txtbxs" runat="server" BackColor="#D4D8DF" Height="25px" Width="250px" Font-Names="Century Gothic"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style4">
<asp:Button ID="Button1" CssClass="sendCV" runat="server" Text="Request CV" Font-Names="Century Gothic" OnClick="Button1_Click" />
</td>
<td> </td>
</tr>
</table>
</div>
</section>
You need to hook up validation controls with the correct button. Right now, button click in first form is causing validation in first contact form as well as second contact form, which is causing Page.IsValid to be false since second form fields are empty and therefore invalid.
So set the validation group of first contact form different from the second contact form as in code below. Then set the ValidationGroup on corresponding validation controls with the same value.
<asp:Button ID="ButtonSend" runat="server" Text="Send" CssClass="btnSend"
Width="80px" OnClick="ButtonSend_Click" UseSubmitBehavior="False"
Font-Names="Century Gothic" ValidationGroup="FirstGroup"/>
<asp:Button ID="Button1" CssClass="sendCV" runat="server"
Text="Request CV" Font-Names="Century Gothic" OnClick="Button1_Click"
ValidationGroup="SecondGroup"/>
NOTE: Make sure that all validation controls have their ValidationGroup also set to appropriate value after you make above code change.

Update panel with Html code post back

I have html control dropdown with multiselection in Update panel. I want a post back on change or complete the multiselctio dropdown option.
<ContentTemplate>
<table class="boxTable1" style="width: 100%;">
<tr style="height: 5px;">
<td colspan="2"> </td>
</tr>
<tr>
<td>
<asp:Label ID="lblBPSIOU" runat="server" Text="BPS IOU"></asp:Label></td>
<td>
<select id="ddlroll" runat="server" multiple="true" onclick="javascript:__doPostBack(this,'')" class="multiselect-group">
</select>
</td>
<td>
<asp:Label ID="lblName" runat="server" Text="Name"></asp:Label></td>
<td>
<select id="ddlName" runat="server" multiple="true" onchange="ddl_OnChange(this);" class="multiselect-group">
</select>
</td>
</tr>
</table>
</table>
</ContentTemplate>
</asp:UpdatePanel>
I want a post back to fill name as per the roll number selection from database.
Pleas help.
Regards,
Ajay
Try adding Triggers to the update panel like as below:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlRoll" />
</Triggers>
here, control name is the dropdown that you have used. i.e., ddlRoll.
you can include this Trigger just before the opening of ContentTemplate tag.
Hope this helps!!
You need to use UniqueID to postback.
<ContentTemplate>
<table class="boxTable1" style="width: 100%;">
<tr style="height: 5px;">
<td colspan="2"> </td>
</tr>
<tr>
<td>
<asp:Label ID="lblBPSIOU" runat="server" Text="BPS IOU"></asp:Label></td>
<td>
<select id="ddlroll" runat="server" multiple="true" onclick="javascript:__doPostBack('<%= ddlroll.UniqueID %>','')" class="multiselect-group">
</select>
</td>
<td>
<asp:Label ID="lblName" runat="server" Text="Name"></asp:Label></td>
<td>
<select id="ddlName" runat="server" multiple="true" onchange="ddl_OnChange(this);" class="multiselect-group">
</select>
</td>
</tr>
</table>
</table>
</ContentTemplate>

ValidatorCalloutExtender and ModalPopupExtender Issues on MasterPage

I have just created a website with a MasterPage. I have two conditions that will illustrate my problem:
Condition 1:
I have added a ModalPopupExtender on website.master. It has three fields and each field has a RequiredFieldValidator and a ValidatorCalloutExtender.
Condition 2:
I have a few different pages where you can click on a registration link. When you click the registration link, a registration form will appear. This form also has RequiredFieldValidators and ValidatorCalloutExtenders for each field.
Problem:
If I open a registration form and want to place my feedback, I click on the feedback button. The feedback modal popup displays. If I click on the submit button without filling the feedback form, it should give me the error in ValidatorCalloutExtender format on the ModalPopupExtender panel. However, it doesnt show me any error but the ValidatorCalloutExtender does show on the registation form along with respective validation.
<cc1:ModalPopupExtender CancelControlID="lnk_cancel" ID="popup_change_password" BackgroundCssClass="modalBackground"
runat="server" TargetControlID="ImageButton1" PopupControlID="panel_change_password">
</cc1:ModalPopupExtender>
<asp:Panel ID="panel_change_password" runat="server" Style="display: none; height: 400px;
width: 400px; padding-left:30px; background-repeat:no-repeat;" BackImageUrl="~/Images/background.gif">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="3" valign="top">
<table cellpadding="0" cellspacing="0" width="400px">
<tr>
<td align="right">
<asp:ImageButton ID="lnk_cancel" runat="server" ImageUrl="Images/close.gif" Height="30px"
Width="30px" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lbl_new_password" runat="server" Text="Your feedback is important to us."
CssClass="login_font1"></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_name" runat="server" Text="Name" CssClass="Label_Styles"></asp:Label>
</td>
<td>
:
</td>
<td>
<asp:TextBox ID="txt_name" runat="server" CssClass="Textbox_Styles"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_email" runat="server" Text="Email Address" CssClass="Label_Styles"></asp:Label>
</td>
<td>
:
</td>
<td>
<asp:TextBox ID="txt_email" runat="server" CssClass="Textbox_Styles"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_comment" runat="server" Text="Comments" CssClass="Label_Styles"></asp:Label>
</td>
<td>
:
</td>
<td>
<asp:TextBox ID="txt_comment" runat="server" CssClass="Textbox_Styles" Height="120px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
</table>
</asp:Panel>
Put the above code in an UpdatePanel with UpdateMode="Conditional" and ChildrenAsTriggers="False".
So it will look something like :
<asp:UpdatePanel ID="sbsModalExtenderUpdatePanel" runat="server" UpdateMode="Conditional"
Visible="False" ChildrenAsTriggers="False">
<ContentTemplate>
<asp:Panel ID="StepByStepBookingPanel" runat="server" Enabled="false" EnableViewState="false"
Style="display: block" CssClass="mediumModalPopup" ScrollBars="Auto" Width="800px"
Height="300px" ViewStateMode="Enabled">
<div id="clientCoordDiv" runat="server">
<table id="StepByStepTable" runat="server">
etc...
</table>
</div>
</asp:Panel>
<ajax:ModalPopupExtender ID="mpeStepByStepBooking" runat="server" BackgroundCssClass="modalBackground"
PopupControlID="StepByStepBookingPanel" CancelControlID="BtnCancel" OnCancelScript="ClearStepByStepPopup"
TargetControlID="hdnStepByStepButton" DropShadow="true" BehaviorID="modalwithinput" />
<asp:CompareValidator ID="ClientCoordinatorCompareValidator" runat="server" ErrorMessage="Please select a Client Coordinator"
ControlToValidate="ddlClientCoordinator" Display="None" Operator="NotEqual" SetFocusOnError="True"
Type="Integer" ValueToCompare="0" ValidationGroup="SelectionRequired">
</asp:CompareValidator>
<asp:CompareValidator ID="CVOCoordinatorCompareValidator" runat="server" ErrorMessage="Please select a CVO Coordinator"
ControlToValidate="ddlCVOCoordinator" Display="None" Operator="NotEqual" ValueToCompare="0"
Type="Integer" SetFocusOnError="True" ValidationGroup="SelectionRequired">
</asp:CompareValidator>
<ajax:ValidatorCalloutExtender ID="CompareClientCoordinatorExt" runat="server" Enabled="True"
TargetControlID="ClientCoordinatorCompareValidator" BehaviorID="ClientValidatorExt">
</ajax:ValidatorCalloutExtender>
<ajax:ValidatorCalloutExtender ID="CVOCoordinatorCompareValidatorExt" BehaviorID="CVOValidatorExt"
runat="server" Enabled="True" TargetControlID="CVOCoordinatorCompareValidator">
</ajax:ValidatorCalloutExtender>
</ContentTemplate>
</asp:UpdatePanel>
This will keep the dialog up while you validate it. Unfortunately, I do not have the full solution since my validator messages are not displaying. So far, from what I am getting on the Net it is a problem with the Ajax library. Ugly!
Oh well, hope this helps someone...

FileUpload not working in update panel(modal popup extender)

i am developing web application and contain modal popup extender in which update panel made and it contain file upload control but file upload control not working in it.
This is my modal popup which contain fileupload control
and my modal popup source code
<cc1:ModalPopupExtender ID="AddNews" runat="server" PopupControlID="pnlPopUp1" BehaviorID="AddNews"
TargetControlID="btnNews" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlPopUp1" runat="server" CssClass="modalPopup" Height="450px" Width="660px"
Style="display:none; z-index: 100000">
<asp:UpdatePanel ID="Upanel1" runat="server">
<ContentTemplate>
<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tr style="height: 35px;">
<td style="width:170px">
</td>
<td style="text-align: center">
<h1>
Add News</h1>
</td>
<td style="text-align: right">
<asp:ImageButton ID="ImageButton2" AlternateText="Close Image" runat="server" ImageUrl="~/images/delete_32i.GIF"
OnClientClick="return closePopup('News')" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblAddNewsError" runat="server" Text="" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td>News Title:</td><td>
<asp:TextBox ID="txtNewTitle" Width="250px" runat="server" MaxLength="500"></asp:TextBox>
</td><td>
<asp:RequiredFieldValidator ID="rfvNewsTitle" runat="server"
ControlToValidate="txtNewTitle" ErrorMessage="*" ToolTip="Enter news title"
ValidationGroup="AddNews"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Upload News Video</td><td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td><td><asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="FileUpload1"
ErrorMessage="Invalid video File"
ValidationExpression="^([0-9a-zA-Z_\-~ :\\])+(.avi|.AVI|.wmv|.WMV|.flv|.FLV|.mpg|.MPG|.mp4|.MP4)$"
ToolTip="Only allow avi, wmv, flv, mpg, mp4 formats video files"
ValidationGroup="AddNews"></asp:RegularExpressionValidator></td>
</tr>
<tr style="height: 5px">
<td>
</td>
</tr>
</table>
<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="width: 675px">
<FCKeditorV2:FCKeditor ID="FCKAddNewsContent" basepath="~/fckeditor/" runat="server" Height="300px"></FCKeditorV2:FCKeditor>
</td>
<td valign="top">
</td>
</tr>
<tr>
<td style="text-align:right">
<asp:Button ID="btnAddNews" runat="server" Text="Add News"
onclick="btnAddNews_Click" ValidationGroup="AddNews" />
<asp:Button ID="btnClose"
runat="server" Text="Close" OnClientClick="return closePopup('News')"
CausesValidation="False" /></td><td></td>
</tr>
</table>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnAddNews" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
as you see my one button also mentioned in postback trigger as i click on this button the result which i got is
can anyone help me out from this problem.
only one thing i just need in web.config and make it working
<httpRuntime executionTimeout="90" maxRequestLength="2000000" useFullyQualifiedRedirectUrl="false" requestLengthDiskThreshold="8192"/>
Point up my answer if you got your solution.
You can set Triggers on update panel. After that you can get file at server side.
<Triggers>
<ajax:PostBackTrigger ControlID="btnAddNews" />
</Triggers>
Hope it will help.

Categories