So i am doing a small web site in ASP.NET and i need to insert some data into a DB. So far i have this, and it isnt any different from what i've seen in the internet:
<h1> Criar Novo Doente </h1>
<asp:SqlDataSource
ID="insertDoente"
runat ="server"
ConnectionString ="<%$ ConnectionStrings:principal %>"
ProviderName = "System.Data.SqlClient"
InsertCommand="INSERT INTO Doentes (do_Nome,do_Sexo,do_DataNascimento,do_IsInternado) VALUES (#do_Nome,#do_Sexo,#do_DataNascimento,0)" >
<InsertParameters>
<asp:Parameter Name="do_Nome" Type="String" />
<asp:Parameter Name="do_Sexo" Type="String" />
<asp:Parameter Name="do_DataNascimento" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
<asp:FormView ID="criarDoente" DefaultMode ="Insert" runat ="server"
DataSourceID="insertDoente"
DataKeyNames="do_Id"
OnItemInserted="MensagemFormView_ItemInserted">
<InsertItemTemplate>
<ul>
<li> </li>
</ul>
<label>Nome: </label> <asp:TextBox ID="nome" runat ="server" MaxLength="100" TextMode="SingleLine" Text='<%# Bind("do_Nome") %>' />
<asp:RequiredFieldValidator ID="NomeRequiredFieldValidator" ErrorMessage="Tem de indicar o nome!"
ControlToValidate="nome" Display="Dynamic" runat="server" />
<br/>
<label>Sexo </label> <asp:RadioButtonList id="Sexo" runat="server" SelectedValue='<%# Bind("do_Sexo") %>'><asp:ListItem id="Masc" Text ="Masculino" Value = "Masculino"></asp:ListItem> <asp:ListItem id="fem" Text ="Feminino" Value ="Feminino"></asp:ListItem> </asp:RadioButtonList>
<br/>
<label>Data de Nascimento: </label> <asp:TextBox ID="dataNasc" runat ="server" MaxLength="100" TextMode="SingleLine" Text='<%# Bind("data") %>' />
<asp:CompareValidator id="dataCompare" ControlToValidate="dataNasc"
Display="Dynamic" Operator="DataTypeCheck"
Type="Date"
ErrorMessage="A data tem de estar no formato YYYY/MM/DD"
ForeColor="Red" runat="server" />
<br />
<asp:Button ID="Criar" runat="server" Text="Criar" CommandName="Insert" />
</InsertItemTemplate>
</asp:FormView>
When i press the button to create, it triggers the onItemInserted event but nothing is added to the database :S Am i doing something wrong ?
EDIT: The fields of the insert commands are ordered the same way they are in the DB, only the ID is missing but that isnt needed or is it?
Related
I'm trying to update the contents of one DropDownList based on the value of 3 other DropDownLists. I have 2 tables, one containing Projects and one containing SubProjects. These 2 have 3 matching Properties:
Year
CountryID
OEID
I want to assign SubProjects to Projects using these matching criteria. Thus my SubProject Adapter has a method that wetches a view containing this data. In the view I try to use following code:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DetailsView ID="DetailsViewProject" runat="server" AutoGenerateRows="False" DataKeyNames="Guid" DataSourceID="ObjectDataSourceProject" DefaultMode="Insert" Height="50px" Width="125px" OnItemInserted="DetailsViewProject_ItemInserted">
<Fields>
<asp:TemplateField HeaderText="Name">
<InsertItemTemplate>
<asp:TextBox ID="TextBoxName" Width="245px" runat="server" Text='<%# Bind("Name") %>' MaxLength="100" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorName" ControlToValidate="TextBoxName" runat="server" ErrorMessage="Please specifiy a Name">*</asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtenderName" runat="server" TargetControlID="RequiredFieldValidatorName" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country">
<InsertItemTemplate>
<asp:DropDownList ID="lstCountries" Width="250px" runat="server" DataSourceID="ObjectDataSourceCountries" DataTextField="Name" DataValueField="ID" SelectedValue='<%#Bind("CountryID") %>' AutoPostBack="True"></asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Organisation Unit">
<InsertItemTemplate>
<asp:DropDownList ID="lstOEs" Width="250px" runat="server" DataSourceID="ObjectDataSourceOEs" DataTextField="Name" DataValueField="ID" SelectedValue='<%#Bind("OrganisationUnitID") %>' OnDataBinding="lstOEs_DataBound" AutoPostBack="True"></asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Year">
<InsertItemTemplate>
<asp:DropDownList ID="lstProjectYears" Width="250px" runat="server" DataSourceID="SqlDataSourceProjectYears" DataTextField="ProjectYear" DataValueField="ProjectYear" SelectedValue='<%#Bind("ProjectYear") %>' OnDataBinding="lstProjectYears_DataBound" AutoPostBack="True"></asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Project">
<InsertItemTemplate>
<asp:DropDownList ID="lstProjectOverall" Width="250px" runat="server" DataTextField="ProjectName" DataSourceID="ObjectDataSourcePOs" DataValueField="ID" SelectedValue='<%#Bind("ProjectOverallID")%>'></asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowCancelButton="False" ShowInsertButton="True" InsertText="Insert" />
</Fields>
</asp:DetailsView>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<asp:ObjectDataSource ID="ObjectDataSourceProject" runat="server" ...and so on
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSourceOEs" runat="server" ...and so on
</asp:ObjectDataSource>
<-- here -->
<asp:ObjectDataSource ID="ObjectDataSourcePOs" runat="server"
SelectMethod="GetProjectsOverallByParameters" TypeName="Projects">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsViewProject$lstProjectYears" name="ProjectYear" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DetailsViewProject$lstOEs" name="OrganisationUnitID" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DetailsViewProject$lstCountries" name="CountryID" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSourceCountries" runat="server" OldValuesParameterFormatString="{0}" SelectMethod="GetCountries" TypeName="Countries"></asp:ObjectDataSource>
<asp:SqlDataSource ID="SqlDataSourceProjectYears" runat="server" ...and so on
</asp:SqlDataSource>
</asp:Content>
But I'm getting this error:
System.InvalidOperationException: 'Databinding methods such as Eval(),
XPath(), and Bind() can only be used in the context of a databound
control.'
Why am I getting this error and how can I solve this? How can I refetch the data from the adapter using either code behind or the aspnet update mechanism?
you have to use property AppendDataBoundItems="True|False" when you have to put existing Item as it is.
I solved the issue:
The problem was, that Project scheme and ProjectOverall scheme didn't match.
I changed the adapter and added an access method for ProjectOverall.
SELECT ID, CountryID, OrganisationUnitID, ProjectYear, ProjectName
FROM wc_ProjectsOverall
WHERE (CountryID = #CountryID) AND (OrganisationUnitID = #OrganisationUnitID) AND (ProjectYear = #ProjectYear)
In ProjectOverall.cs:
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select, false)]
public WebControlling.ProjectsOverallDataTable GetProjectsOverallByAttributes(Guid CountryID, Guid OrganisationUnitID, Int32 ProjectYear)
{
if (CountryID == null || OrganisationUnitID == null || ProjectYear == 0)
return new WebControlling.ProjectsOverallDataTable();
return Adapter.GetProjectsByAttribute(CountryID, OrganisationUnitID, ProjectYear);
}
In the view ProjectAdd.aspx:
<asp:TemplateField HeaderText="Project">
<InsertItemTemplate>
<asp:DropDownList ID="lstProjectOverall" Width="250px" runat="server" DataTextField="ProjectName" DataSourceID="ObjectDataSourcePOs" DataValueField="ID" AppendDataBoundItems="False"></asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:ObjectDataSource ID="ObjectDataSourceProject" runat="server" InsertMethod="AddProject" OldValuesParameterFormatString="{0}" SelectMethod="GetProjects" TypeName="Projects" OnInserting="ObjectDataSourceProject_Inserting" >
<InsertParameters>
<asp:Parameter Name="CountryID" Type="Object" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Objective" Type="String" />
<asp:Parameter Name="ObjectiveQuantitativ" Type="String"/>
<asp:Parameter Name="ProjectYear" Type="Int32" />
<asp:Parameter Name="BaseCampaign" Type="Boolean" />
<asp:Parameter Name="ManagerID" Type="Object" />
<asp:Parameter Name="OrganisationUnitID" Type="Object" />
<%-- This parameter is different because the ProjectOverall ID is not part of the Project model, thus we insert the DropDownList value --%>
<asp:ControlParameter ControlID="DetailsViewProject$lstProjectOverall" name="ID" PropertyName="SelectedValue"/>
</InsertParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSourcePOs" runat="server"
SelectMethod="GetProjectsOverallByAttributes" TypeName="ProjectsOverall">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsViewProject$lstProjectYears" name="ProjectYear" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DetailsViewProject$lstOEs" name="OrganisationUnitID" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DetailsViewProject$lstCountries" name="CountryID" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:ObjectDataSource>
And that solved my issue.
I am at a total loss here! Perhaps someone will see something that I'm missing. I'm using this same code else where and it works just fine. The purpose is to seed an Edit mode FromView with data that I want to supply for the user. In this case I'm not allowing user to change the information that I'm supplying.
What I get when I try to run this is:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference
not set to an instance of an object.
My code behind checks for null reference so I'm not sure what I can do to correct this. And this works elsewhere in my code (variables different of course).
Here is a fragment from the aspx page and then the C# code behind that go with it.
<asp:Panel runat="server" ID="RejectDetailPnl" Visible="false">
<asp:Button ID="RejectBtn" runat="server" OnClick="RejectBtn_Click" BackColor="#ff0000" ForeColor="#ffffff" Text="Click To Reject" />
<asp:FormView ID="RejSubmittFV" runat="server" OnInit="RejSubmittFV_Init" DefaultMode="Edit" DataSourceID="RejSubmitDS">
<EditItemTemplate>
CAssetID:
<asp:TextBox Text='<%# Bind("CAssetID") %>' runat="server" BackColor="LightGray" ReadOnly="true" ID="CAssetIDTextBox" /><br />
Reason:
<asp:TextBox Text='<%# Bind("Reason") %>' runat="server" ID="ReasonTextBox" Width="500" Height="500" TextMode="MultiLine" OnTextChanged="ReasonTextBox_TextChanged" /><br />
Source:
<asp:TextBox Text='<%# Bind("Source") %>' runat="server" BackColor="LightGray" ReadOnly="true" ID="SourceTextBox" /><br />
RejBy:
<asp:TextBox Text='<%# Bind("RejBy") %>' runat="server" BackColor="LightGray" ReadOnly="true" ID="RejByTextBox" /><br />
RejDT:
<asp:TextBox Text='<%# Bind("RejDT") %>' runat="server" BackColor="LightGray" ReadOnly="true" ID="RejDTTextBox" /><br />
<asp:LinkButton runat="server" Text="Update" o CommandName="Update" ID="UpdateButton" CausesValidation="True" />
</EditItemTemplate>
<InsertItemTemplate>
CAssetID:
<asp:TextBox Text='<%# Bind("CAssetID") %>' runat="server" ID="CAssetIDTextBox" /><br />
Reason:
<asp:TextBox Text='<%# Bind("Reason") %>' runat="server" ID="ReasonTextBox" /><br />
Source:
<asp:TextBox Text='<%# Bind("Source") %>' runat="server" ID="SourceTextBox" /><br />
RejBy:
<asp:TextBox Text='<%# Bind("RejBy") %>' runat="server" ID="RejByTextBox" /><br />
RejDT:
<asp:TextBox Text='<%# Bind("RejDT") %>' runat="server" ID="RejDTTextBox" /><br />
<asp:LinkButton runat="server" Text="Insert" CommandName="Insert" ID="InsertButton" CausesValidation="True" /> <asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="InsertCancelButton" CausesValidation="False" />
</InsertItemTemplate>
<ItemTemplate>
CAssetID:
<asp:Label Text='<%# Bind("CAssetID") %>' runat="server" ID="CAssetIDLabel" /><br />
Reason:
<asp:Label Text='<%# Bind("Reason") %>' runat="server" ID="ReasonLabel" /><br />
Source:
<asp:Label Text='<%# Bind("Source") %>' runat="server" ID="SourceLabel" /><br />
RejBy:
<asp:Label Text='<%# Bind("RejBy") %>' runat="server" ID="RejByLabel" /><br />
RejDT:
<asp:Label Text='<%# Bind("RejDT") %>' runat="server" ID="RejDTLabel" /><br />
<asp:LinkButton runat="server" Text="Edit" CommandName="Edit" ID="EditButton" CausesValidation="False" />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource runat="server" ID="RejSubmitDS" ConnectionString="Data Source=gbaptccsr01;Initial Catalog=CInTracDB;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT CAssetID, Reason, Source, RejBy, RejDT FROM RejFailCtrl WHERE (CAssetID = #CAssetID)" UpdateCommand="UPDATE RejFailCtrl SET Reason = #Reason, Source = #Source, RejBy = #RejBy, RejDT = #RejDT WHERE (CAssetID = #CAssetID)">
<SelectParameters>
<asp:SessionParameter SessionField="ChangeRecord" Name="CAssetID"></asp:SessionParameter>
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Reason"></asp:Parameter>
<asp:Parameter Name="Source"></asp:Parameter>
<asp:Parameter Name="RejBy"></asp:Parameter>
<asp:Parameter Name="RejDT"></asp:Parameter>
<asp:Parameter Name="CAssetID"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<br />
<asp:Button runat="server" ID="RejectResetBtn" Visible="false" OnClick="RejectResetBtn_Click" Text="*** After Entering your Comment Click this bar!! ****" ForeColor="White" BackColor="Red" />
</asp:Panel>
The C# code behind and the choke point is:
TextBox uname = (TextBox)RejSubmittFV.Row.FindControl("RejByTextBox");
There are two other points I have tested by commenting out sections that also fail in this code block. Basically every time I repeat this code sequence it renders this error. Here is the full code block for your reference:
protected void RejectBtn_Click(object sender, EventArgs e)
{
TextBox uname = (TextBox)RejSubmittFV.Row.FindControl("RejByTextBox");
if (uname != null)
uname.Text = Session["RegUser"].ToString();
TextBox usource = (TextBox)RejSubmittFV.Row.FindControl("SourceTextBox");
if (usource != null)
usource.Text = "CInTrac";
TextBox udate = (TextBox)RejSubmittFV.Row.FindControl("RejDTTextBox");
if (udate != null)
udate.Text = DateTime.Now.ToString("MM/dd/yyyy");
}
Like I mentioned this procedure is working perfectly elsewhere so I don't have a clue why it isn't here.
Any ideas would be greatly appreciate!
I'm seeing two items that could be null which you are expecting to exist:
RejSubmittFV and the .Row property. They're not assigned, in the code you've provided, so we cannot be sure that you're initializing that object.
Session["RegUser"] which isn't tested for null before you're trying to call .ToString() on it.
If you're able to step through with a debugger, these are the kinds of operations to look for. You can either add a watch to these values or you can simply hover your mouse and see if each reference is null.
I never came up with a real answer for this issue! What I ended up doing to work around the problem was to eliminate the ForrView and simple sit the 5 data fields in a panel that I controlled the visibility with by ID which eliminated the issue of having to navigate the FindControl. This lead to abandoning the SqlDataSource and doing my update via a stored procedure and 100% with code behind and it was a LOT cleaner as a result.
// Update the Control file
SqlConnection UpdRejConnection = new SqlConnection("Data Source=GBAPTCCSR01;Initial Catalog=CInTracDB;Integrated Security=True");
SqlCommand Updcmd = new SqlCommand();
SqlDataReader Updreader;
Updcmd.Parameters.AddWithValue("#CAssetID", Session["ChangeRecord"]);
Updcmd.Parameters.AddWithValue("#Reason", ReasonTextBox.Text.ToString());
Updcmd.Parameters.AddWithValue("#Rejby", RejByTextBox.Text.ToString());
Updcmd.Parameters.AddWithValue("#Source", SourceTextBox.Text.ToString());
Updcmd.Parameters.AddWithValue("#RejDT", RejDTTextBox.Text.ToString());
Updcmd.CommandText = "usp_UpdRejCtrl";
Updcmd.CommandType = CommandType.StoredProcedure;
Updcmd.Connection = UpdRejConnection;
UpdRejConnection.Open();
Updreader = Updcmd.ExecuteReader();
UpdRejConnection.Close();
I'm trying to bind the selected value from the date picker to an asp textbox but I have this Error: 'this._targetEl.value.length' is null or not an object.
Here's the code:
<InsertItemTemplate>
Book Title:
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="booktitleDataSource" DataTextField="booktitle"
DataValueField="bookid" SelectedValue='<%# Bind("bookid", "{0}") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="booktitleDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [bookid], [booktitle] FROM [TblBooks]">
</asp:SqlDataSource>
<br />
Employee PIN:
<asp:TextBox ID="employeeidTextBox" runat="server"
Text='<%# Bind("employeeid") %>' />
<br />
Department:
<asp:TextBox ID="departmentTextBox" runat="server"
Text='<%# Bind("department") %>' />
<br />
Date borrowed:
<asp:TextBox ID="dateborrowedTextBox" runat="server" Text='<%# Bind("dateborrowed") %>' />
<%--<input type="text" name="dateborrowedTextBox" readonly="readonly" id="dateborrowedTextBox">--%>
Date Picker
<br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
It was working when I
tried using <input type="text" name="dateborrowed" readonly="readonly" id="dateborrowedTextBox"> but when I tried using the asp:TextBox I cant pass the selected value from date picker to the textbox. So where did I go wrong? Is there a way to program the date picker link to call the popup calendar? (its in Java btw)
Help would be much appreciated!
Thanks in advance.
Nested controls have their ID/name attributes overwritten with an absolute unique id/name when rendered. When your javascript is attempting to reference the TextBox its name won't actually be 'dateborrowedTextBox' it will be something like '...$ctl00$dateborrowedTextBox'.
If your javascript is finding the control by name, this might clear up the issue:
Date Picker
Otherwise try this if its finding the control by id:
Date Picker
Found the solution. I think it can only read asp.net syntax not classic asp.
<asp:TextBox ID="reservedateTextBox" runat="server" Text='<%# Bind("reservedate") %>' />
<%--Date Picker--%>
Date Picker
I'm having some problem binding the value of a date picker to a textbox in formview asp.net. I've tried to a put a date picker in ASP.NET and JavaScript which calls on a class file in calendar.css so far it can display the date but if I tried to insert it to a record it always return null. So how can I bind it so it can add the date value to the record?
Help would be much appreciated.
Thanks in advance ;)
Here's a sample of my code. I want to bind the 'input text' to the 'dateborrowedTextBox'
<InsertItemTemplate>
Book Title:
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="booktitleDataSource" DataTextField="booktitle"
DataValueField="bookid" SelectedValue='<%# Bind("bookid", "{0}") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="booktitleDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [bookid], [booktitle] FROM [TblBooks]">
</asp:SqlDataSource>
<br />
Employee PIN:
<asp:TextBox ID="employeeidTextBox" runat="server"
Text='<%# Bind("employeeid") %>' />
<br />
Department:
<asp:TextBox ID="departmentTextBox" runat="server"
Text='<%# Bind("department") %>' />
<br />
Date borrowed:
<%--<asp:TextBox ID="dateborrowedTextBox" runat="server"
Text='<%# Bind("dateborrowed") %>' />--%>
<input type="text" name="dateborrowedTextBox" readonly="readonly" id="dateborrowedTextBox">
<a href="#" onclick="cdp1.showCalendar(this, 'dateborrowedTextBox'); return false;">Date Picker
</a>
<br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
The client-side IDs of the ASP.NET controls are not going to be translated as cleanly as you are hoping.
You need to do one of two things, both of which can be found here.
Date Picker
Or, you could add a Link control and set the actions that way (the link I gave you does it with an image control). It's up to you.
Just found my answer. ASP.NET cant read Javascript normally so CT100 and some dollar sign will do the trick ;)
Date Picker
In the form in aspx I have two textbox and one image button for each textbox.
I need validation the value for each textbox in a separate way and for this I have for each image button linked to a different event.
For this I have finded in google and I have tried this tutorial:
http://www.c-sharpcorner.com/Blogs/3625/use-of-validation-group-in-Asp-Net.aspx
But in my form the Validation Group in asp.net not working and I don't understand the reason.
What does not work are the warning messages that indicate required fields.
What's wrong?
My code aspx below, thank you in advance.
<form id="form1" runat="server">
<div>
<asp:textbox id="TextBox1" runat="server" width="100" cssclass="ddl_Class" validationgroup="First"></asp:textbox>
<asp:requiredfieldvalidator id="RequiredFieldValidator3" runat="server" controltovalidate="TextBox1"
errormessage="Error in TextBox1" text="***" display="None" validationgroup="First"></asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id="RegularExpressionValidator4" runat="server" controltovalidate="TextBox1"
errormessage="TextBox1 only number" text="***" display="None" validationexpression="^\d+$" validationgroup="First"></asp:regularexpressionvalidator>
<asp:imagebutton id="btnSave1" runat="server" validationgroup="First" onclick="ButtonSave1_Click" imageurl="/Images/save_button.gif" onclientclick="if (!confirm('Confirm?')) return false;" />
<asp:textbox id="TextBox2" runat="server" width="100" cssclass="ddl_Class" validationgroup="Second"></asp:textbox>
<asp:requiredfieldvalidator id="RequiredFieldValidator4" runat="server" controltovalidate="TextBox2"
errormessage="Error " text="***" display="None" validationgroup="Second"></asp:requiredfieldvalidator>
<asp:imagebutton id="btnSave2" runat="server" validationgroup="Second" onclick="ButtonSave2_Click" imageurl="/Images/save_button.gif" onclientclick="if (!confirm('Confirm?')) return false;" />
</div>
<asp:validationsummary id="First" runat="Server" showmessagebox="true" cssclass="validation-summary-errors" />
<asp:validationsummary id="Second" runat="Server" showmessagebox="true" cssclass="validation-summary-errors" />
</form>
I have verified your code, only problem that I identified is missing validation group in validation summary tag.
See below:
<asp:validationsummary id="First" validationgroup="First" runat="Server" showmessagebox="true" cssclass="validation-summary-errors" />
<asp:validationsummary id="Second" validationgroup="Second" runat="Server" showmessagebox="true" cssclass="validation-summary-errors" />
Hope this will work