Validation group being called by all buttons - asp.net

I have a simple 2 tab panel setup with 2 validation groups. My problem is that my buttons fire both validation groups.
<cc1:TabPanel ID="TP2" runat="server" HeaderText="" Enabled="true">
<HeaderTemplate>Loan Main</HeaderTemplate>
<ContentTemplate>
<table cellpadding="3" cellspacing="1">
<tr>
<td style="text-align: right"> Quality:</td>
<td><asp:DropDownList ID="ddlAssignedRep" runat="server" DataSourceID="SqlDataSourceAssignedRep"
ValidationGroup="TP2" DataTextField="CreatedBy" DataValueField="CreatedBySFID"
AppendDataBoundItems="True"> </asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceAssignedRep" runat="server" ConnectionString="<%$ ConnectionStrings:EUCNET00720 %>"
SelectCommand="SELECT distinct [CreatedBySFID], [CreatedBy] FROM [tblRefiActions] WHERE ([RefiPkey] = #RefiPkey) ORDER BY [CreatedBy]">
<SelectParameters>
<asp:QueryStringParameter Name="RefiPkey" QueryStringField="Pkey" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource></td>
</tr>
<tr>
<td style="text-align: right"><asp:Button ID="btnSave" runat="server" ValidationGroup="TP2" Text="Save" /></td>
<td> </td>
</tr>
</table>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Quality measure is required."
ValidationGroup="TP2" ControlToValidate="ddlQuality" Display="None" SetFocusOnError="True"></asp:RequiredFieldValidator>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TP3" runat="server" HeaderText="" Enabled="true">
<HeaderTemplate>Short Payoff</HeaderTemplate>
<ContentTemplate>
<table cellpadding="3" cellspacing="1">
<tr>
<td style="text-align: right"> Amount Short:</td>
<td><asp:TextBox ID="txtShortPayoffAmount" ValidationGroup="TP3" runat="server" Columns="12" MaxLength="12"></asp:TextBox></td>
</tr>
<tr>
<td style="text-align: right"> </td>
<td><asp:Button ID="btnPayoffUpdate" runat="server" Text="Update" ValidationGroup="TP3" /></td>
</tr>
</table>
<br />
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Amount can only contain numbers and a single decimal point." ControlToValidate="txtShortPayoffAmount"
ValidationGroup="TP3" Display="None" SetFocusOnError="True"
ValidationExpression="^(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$"> </asp:RegularExpressionValidator>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" ShowMessageBox="True"
ValidationGroup="TP2" ShowSummary="False" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" DisplayMode="List"
ValidationGroup="TP3" ShowMessageBox="True" ShowSummary="False" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<cc1:ModalPopupExtender ID="ProgressBarModalPopupExtender" runat="server" BackgroundCssClass="ModalBackground" BehaviorID="ProgressBarModalPopupExtender" TargetControlID="hiddenField1" PopupControlID="Panel1" />
<asp:Panel ID="Panel1" runat="server" Style="display: none; background-color: #C0C0C0;"> <img id="MyImage" src="../Images/Vista_Searching_Bar.gif" alt="" />
<div id="processMessage" style="width: 200px;"> <br />
<br />
Loading...<br />
<br />
</div>
</asp:Panel>
<asp:HiddenField ID="HiddenField1" runat="server" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
<script type="text/javascript">
function StartProgressBar() {
var tp2 = Page_ClientValidate("TP2")
if (tp2 == true) {
var myExtender = $find( ProgressBarModalPopupExtender );
ProgressImg = document.getElementById( MyImage );
setTimeout("ProgressImg.src = ProgressImg.src", 10);
myExtender.show();
return true;
}
}
</script>

I think your validation group names are off. The button and validation summary say the validation group "TabPanel3" "TabPanel1" but your validators say "TP3" and "TP2"
Also you need to make sure that the javascript in your button click is having the ValidationGroup passed in. It looks as though right now it is calling "TP2" no matter which button you click based on your comments below.
Try this for your javascript
function StartProgressBar(ValidationGroup) {
if (Page_ClientValidate(ValidationGroup)) {
//do stuff here on valid
return true;
}
else {
return false;
}
}
Then your button click code should be something like this:
<asp:Button ID="btnSave" OnClientClick="return StartProgressBar('TP2');" runat="server" ValidationGroup="TP2" Text="Save" />
and
<asp:Button ID="btnPayoffUpdate" OnClientClick="return StartProgressBar('TP3');" runat="server" Text="Update" ValidationGroup="TP3" />
Make each click return the value of the validation, that way the click will not continue, because if you return true from that function even if the validation fails I am not sure it will stop since you called the validation manually, I don't know if it will run again. But if you return false it will stop the click, or at least it should.

Related

ASP.NET Label Inside UpdatePanel Not Updating on Selected Index Changed

I am new to ASP.NET and I'm trying to get a Label to update with some information that is grabbed when I hit On selected index changed. The On selected index changed function is called and returns just fine (I've debugged and stepped through the whole thing). The only thing that doesn't work is where I set the text of the Labels I'm trying to update.
This is the function that gets called on the On selected index changed click:
protected void OnClosetIndexChanged(object sender, EventArgs e)
{
{
UpdatePanel updatePanel1 = Row.FindControl("UpdatePanel1") as UpdatePanel;
Label oldSourceQuantity = (Label)Row.FindControl("lblQuantity");
oldSourceQuantity.Text = "0";//Trying to force a value
updatePanel1.Update();
}
}
I know it goes into the if and tries to set the text but nothing happens on the client side.
This is the UpdatePanel I have:
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%" style="background:#F5F5F5" >
<div id="div<%# Eval("componente_id") %>" style="overflow:auto; display:none; position: relative; left: 15px; overflow: auto">
<div class="ExpandTableHeader">
Cambiar la cantidad
</div>
<div class="body">
<label for="validationOfTypeID">Armario:</label>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:DropDownList ID="drCloset" AppendDataBoundItems="True" runat="server" Width="20%" Height="30px" AutoPostBack="true" OnSelectedIndexChanged = "OnClosetIndexChanged"></asp:DropDownList>
<br/>
<label for="validationOfTypeID" visible="false" >cajon</label> <br/>
<asp:DropDownList ID = "drDrawer" AutoPostBack="true" runat="server" Width="20%" Height="30px" >
</asp:DropDownList>
<asp:Label ID="lblQuantity" runat="server" Text=""></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostbackTrigger ControlID="drCloset" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<label for="validationOfTypeID"></label>
<asp:DropDownList Height="30px" ID="drOperation" runat="server" >
<asp:ListItem>+</asp:ListItem>
<asp:ListItem>-</asp:ListItem>
</asp:DropDownList>
<asp:TextBox width="50px" ID="txtChangeQuantity" runat="server" TextMode="Number" min="0" step="1" Value="0" ></asp:TextBox>
<asp:Label ID="lblTotal" runat="server" Text=""></asp:Label>
<br/>
</br>
<asp:Button class="btn btn-primary" ID="btnConfirmPurchases" runat="server" Text="Validar" AutoPostback="true" width="20%" />
</div>
<asp:DetailsView id="DetailsView1" DataKeyNames="componente_id" Runat="server" Width="300px" Font-Names="Calibri"/>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>

Update Panel, Update Progress and DropDown List

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
<Services>
<asp:ServiceReference Path="Machine.asmx" />
</asp:ScriptManager>
<div align="center" style="width:auto" >
<asp:UpdatePanel ID="up1" runat="server" Visible="true" UpdateMode="Conditional">
<ContentTemplate>
<table class="nav-justified" border="1" id="table1">
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Select Search Criteria"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlSearchCriteria" runat="server" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="ddlSearchCriteria_SelectedIndexChanged" Height="30px" Width="200px">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">All</asp:ListItem>
<asp:ListItem Value="2">Data Center</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr id="trDC" runat="server" visible="false"> <td>
<asp:Label ID="lblRegion" runat="server" Text="Select DataCenter"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlDC" runat="server" AutoPostBack="false" EnableViewState="true" OnSelectedIndexChanged="ddlDC_SelectedIndexChanged" Height="30px" Width="200px">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">a </asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr id="tr1" runat="server" visible="false" >
<td>
<asp:Label ID="lblOrder" runat="server" Text="Order For SOEID"></asp:Label>
</td>
<td >
<asp:TextBox ID="txtOrderFor" runat="server" Height="20px" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="up1" DisplayAfter="0" DynamicLayout="false">
<ProgressTemplate>
<div style="position:absolute; left:45%;">
<div style="position:relative; left:45%;">
<table border="0" align="center">
<tr>
<td>
<img alt=""src="img/loading.gif" height="50px" width="50px" />
</td>
</tr>
</table>
<center>
Please wait...
</center>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
<asp:UpdatePanel ID="up2" runat="server">
<ContentTemplate>
<asp:Label ID="lblRows" runat="server" Font-Size="Large" Visible="false" ></asp:Label>
<asp:GridView ID="gvDetails" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="3" CssClass="bootstrap dataTables_wrapper" DataKeyNames="Order_Item_Id” EnableViewState="false" HeaderStyle-HorizontalAlign="Left" OnPageIndexChanging="gvDetails_PageIndexChanging" OnRowCommand="gvDetails_RowCommand" OnRowDataBound="gvDetails_RowDataBound" PageSize="15" ShowHeaderWhenEmpty="true" Visible="true" Width="100%">
<Columns>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkBox1" runat="server" AutoPostBack="true" OnCheckedChanged="Check_Clicked"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Order_Item_Id" HeaderStyle-HorizontalAlign="Left" HeaderText="Order Id" />
</Columns>
</asp:GridView>
</div>
<asp:Button ID="Button4" runat="server" Font-Bold="True" Font-Size="XX-Large" OnClick="Button4_Click" Text="Export To Excel" visible="false" />
<asp:Button ID="Button3" runat="server" Font-Bold="True" Font-Size="XX-Large" OnClick="Button3_Click" Text="Submit" Visible="false" />
<asp:Button ID="Button1" runat="server" Font-Bold="True" Font-Size="XX-Large" OnClick="Button1_Click" Text="Cancel" Visible="false" />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button4" />
<asp:PostBackTrigger ControlID="Button3" />
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
I have two update panel and 1 update progress on my aspx page. My first update panel contains two dropdown, on change of first dropdown, second populates and also there is a submit button in the update panel.
When I use selectedindexchange of dropdown, Autopostback occurs, update progress works but I don't want it to work on that event. It should work only on the submit click.
Second update panel contains the data to be shown on click of submit button.
Also,My update progress is not in any of the update panel, it is in a div between both the update panel.

Is it possible to add some text or some tag under below the create user wizard steps button (previous, next, finish, etc) in createuserwizard??

enter code here`<asp:WizardStep ID="CreateUserWizardStep0" runat="server" StepType="Start">
<h1>Bir Hesap Seçin</h1>
<table>
<tr>
<td>
<asp:Label ID="AccountNameLabel" CssClass="grey" runat="server" AssociatedControlID="SearchAccount" >
Kullanıcı Adı:</asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="SearchAccount" CssClass="field" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator Visible="true" ID="RequiredFieldValidator1" ControlToValidate="SearchAccount" Display="None" ValidationGroup="kayitFormu" runat="server" ErrorMessage="Girmiş Olduğunuz Hesap Adı Kullanımdadır. Lütfen farklı bir hesap adı deneyiniz."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="SearchAccountMessage" style="width:400px;" runat="server" ForeColor="red" />
</td>
</tr>
</table>
</asp:WizardStep>`
Is it possible to add some text or some tag under below the create user wizard steps button (previous, next, finish, etc) in createuserwizard??
Have a look at the StepNavigationTemplate. This site should help
I'm not sure if this is what you're looking for, but you can use the navigation templates:
<StartNavigationTemplate>
<asp:Button ID="btnStepNext" runat="server" Text="Next" Width="110" CommandName="MoveNext" CausesValidation="true" />
</StartNavigationTemplate>
<StepNavigationTemplate>
<asp:Button ID="btnStepPrevious" runat="server" Text="Previous" Width="110" CommandName="MovePrevious" CausesValidation="false" />
<asp:Button ID="btnStepNext" runat="server" Text="Next" Width="110" CommandName="MoveNext" CausesValidation="true" />
</StepNavigationTemplate>
<FinishNavigationTemplate>
<asp:Button ID="btnStepPrevious" runat="server" Text="Previous" Width="110" CommandName="MovePrevious" CausesValidation="false" />
<asp:Button ID="btnStepFinish" runat="server" Text="Finish" Width="120" CommandName="MoveComplete" CausesValidation="true" />
</FinishNavigationTemplate>

Modal Popup Error

I have a DataList that has a link button and I want this link button envoke a modal popup. I've copied the mpe code from another application where it works in a gridview. The error is thrown as soon as page is openned and each time the link button is clicked. The error is thrown in the ScriptResource file: "Microsoft JScript runtime error: Sys.ArgumentNullException: Value cannot be null.
Parameter name: elements". I understand something has null value but not sure what. Page has over a thousand lines so I'll just paste the part I'm working on.
<ItemTemplate>
<tr class="AssetMngnt-trHeaderRow_bgColor">
<td valign="top">
<asp:Label ID="lblIdent" runat="server" Text='<%# Eval("Printer_Ident") %>' Visible="false"></asp:Label>
</td>
<td>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False" CommandName="Select" Text="Edit" />
</td>
<td valign="top" nowrap>
<asp:Label ID="lblName" Text='<%# Eval("Network_Name") %>' runat="server" />
</td>
<td valign="top">
<asp:LinkButton ID="lbPrinterModel"
runat="server" CausesValidation="False" CommandName="Select" CommandArgument="ShowAsset"
Text='<%# Eval("Printer_Mfg") + " " + (string)Eval("Printer_Model") %>' />
</td>
<td valign="top">
<asp:Label ID="lblLocation" Text='<%# Eval("Location") %>' runat="server" />
</td>
<td>
<asp:LinkButton ID="LinkButton1"
runat="server" CausesValidation="False" CommandName="Select" CommandArgument="IssueToners"
Text="Issue Toners" />
<asp:Button runat="server" ID="btnShowPopup" style="display:none" />
<ajaxToolkit:ModalPopupExtender runat="server" id="mpeIssueToners"
TargetControlID="btnShowPopup"
PopupControlID="pnlFvIssueTonersModal"
CancelControlID="UpdateCancelButton"
BackgroundCssClass="modalBackground" >
</ajaxToolkit:ModalPopupExtender>
</td>
</tr>
</ItemTemplate>
<asp:Panel runat="server" ID="pnlFvIssueTonersModal" Visible="true" style="display:none">
<asp:Panel runat="server" ID="pnlFvIssueToners" Visible="true">
<div id="AssetMngnt-FloatLeft_alt"">
<!-- ISSUE TONERS FORM VIEW ******************************************************************************** -->
<asp:FormView ID="fvIssueCartridges" runat="server" DataSourceID="ODSIssueCartridges"
OnItemUpdating="fvIssueCartridges_OnItemUpdating" OnItemUpdated="FormView1_Display_Update_Msg"
EnableViewState="False"
EmptyDataRowStyle-CssClass="AssetMngnt-panelRO" >
<EditItemTemplate>
</EditItemTemplate>
</asp:FormView>
<!-- END ISSUE TONERS FORM VIEW **************************************************************************** -->
</div>
</asp:Panel>
<ajaxToolKit:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="mdlPopup" runat="server"
TargetControlID="div" PopupControlID="div" CancelControlID="btnNo"
OnCancelScript="cancelClick();" BackgroundCssClass="modalBackground" />
<div id="div" runat="server" align="center" class="confirm" style="display:none">
<asp:Label Text="Form is empty - empty records are not allowed."
ForeColor="#000000" runat="server" ID="Label3" /><br />
<asp:Button ID="btnNo" runat="server" Text="Ok" Width="50px" />
</div>
</asp:Panel>
The ModalPopupExtender1 takes care of things inside the FormView.
Thanks,
Risho

File Upload is not working

I'm using file upload in my site. I'm uploading word Document(Doc,Docx). Suddenly, it's not working. It is not getting the filename. It is showing empty!!! My Code is as follows:
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<table width="100%" align="center">
<tr>
<td style="height: 21px" align="center">
<span class="lbl"></span>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Button ID="btnResumedload" Text="Download Resume" runat="server" BackColor="Maroon"
ForeColor="White" Font-Bold="true" OnClick="btnResumedload_Click" Height="27px"
Width="195px" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="center">
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:Button ID="btnUploadnew" Text="Upload New" runat="server" BackColor="Maroon"
ForeColor="White" Font-Bold="true" OnClick="btnUploadnew_Click" Height="30px"
Width="198px" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="center">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:Button ID="btnDel" Height="30px" Width="198px" OnClientClick="return confirm('Are you sure?');"
BackColor="Maroon" ForeColor="White" Font-Bold="true" Text="Delete Resume" runat="server"
OnClick="btnDel_Click"></asp:Button>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="center">
<asp:Label ID="lblmsg" runat="server" Font-Bold="True" ForeColor="Red" Visible="False"
Height="17px" Width="855px"></asp:Label>
</td>
</tr>
<tr>
<td align="center">
<span class="txt">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%--<ajaxToolkit:AsyncFileUpload ID="fpResumenew" runat="server" Visible="false" />--%>
<asp:FileUpload ID="fpResumenew" runat="server" Visible="false" Width="226px" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
</span>
</td>
</tr>
<tr>
<td align="center">
</td>
</tr>
<tr>
<td style="vertical-align: top" align="center">
<%--<asp:Button ID="btnUpload" Font-Bold="true" DisabledText="Processing..." Visible="false"
Text="Upload" BackColor="Maroon" ForeColor="White" runat="server" OnClick="btnUpload_Click" />--%>
<cc1:ClickOnceButton ID="btnUpload" Font-Bold="true" DisabledText="Processing..."
Visible="false" Text="Upload" BackColor="Maroon" ForeColor="White" runat="server"
OnClick="btnUpload_Click" DisableAfterClick="True" />
</td>
</tr>
</table>
protected void btn_Click(object sender, EventArgs e)
{
string strfilename = fp.FileName.ToString();
if (fp.PostedFile.FileName.Trim().Length != 0)
{
binary = new byte[fp.PostedFile.ContentLength];
binary = fp.FileBytes;
doc = fp.FileName;
contenttype = fp.PostedFile.ContentType;
}
}
Just a sample!!!
Nothing works for me.. Problem is that I'm using three more buttons in the same page. The other buttons initializing the file upload control. So, when clicking the upload button, the file name is empty. So, I used another page for uploading the word document. Now, it is working.. !! Anyhow, I need the solution for this!! Anyone give me idea!!
Hai vaishu
FileUpload controls are not compatible with UpdatePanel when they are used to upload files as part of an asynchronous postback.
Just check the AJAX documentation. The FileUpload control is not supported inside an UpdatePanel (http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx):
or
use asp:postbacktrigger instead of asyncpostbacktrigger
<asp:updatepanel runat="server" id="UpdatePanel1">
<contenttemplate>
<asp:FileUpload runat="server" id="FileUpload1" />
<asp:button runat="server" id="ButtonSubmit" text="Postback" />
</contenttemplate>
<triggers>
<asp:postbacktrigger controlid="ButtonSubmit" />
</triggers>
</asp:updatepanel>
or
use ajax for asynchronous file upload:
http://www.asp.net/(S(fu2l2uzphr2u3u45q2dnez55))/ajax/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx
The reason that the postback trigger is not working in your case is because the FileUpload Control is set to visible=false. If you use display:none instead, the postback trigger will work.
This works just fine, I finally solved the issue... the ButtonSubmit is reload by the trigger so the page got the info from the control.
<asp:updatepanel runat="server" id="UpdatePanel1">
<contenttemplate>
<asp:FileUpload runat="server" id="FileUpload1" />
<asp:button runat="server" id="ButtonSubmit" text="Postback" />
</contenttemplate>
<triggers>
<asp:postbacktrigger controlid="ButtonSubmit" />
</triggers>
</asp:updatepanel>

Resources