Click here to Skip to main content
16,004,974 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Validation-------urgent Pin
Priya_20076-Sep-07 1:41
Priya_20076-Sep-07 1:41 
GeneralRe: Validation-------urgent Pin
Shujaat Ullah Khan6-Sep-07 1:51
Shujaat Ullah Khan6-Sep-07 1:51 
QuestionAccessing an ImageField in a GridView programmatically Pin
Rohde5-Sep-07 23:37
Rohde5-Sep-07 23:37 
AnswerRe: Accessing an ImageField in a GridView programmatically Pin
Parwej Ahamad5-Sep-07 23:59
professionalParwej Ahamad5-Sep-07 23:59 
GeneralRe: Accessing an ImageField in a GridView programmatically Pin
Rohde6-Sep-07 0:15
Rohde6-Sep-07 0:15 
Questioncustom event handler problem Pin
ekynox5-Sep-07 23:25
ekynox5-Sep-07 23:25 
AnswerRe: custom event handler problem Pin
ekynox6-Sep-07 11:03
ekynox6-Sep-07 11:03 
QuestionDetailsView loses controls state and binding after an exception occurs Pin
Alex Getman5-Sep-07 22:49
Alex Getman5-Sep-07 22:49 
Hi.

I'm using ASP.NET 2.0 and MS SQL Server 2005 environment. I'm developing an aspx page which is using DetailsView to insert data.
There are several TemplateFields are located at the DetailsView control. These Template fields containing TextBox and DropDownlList controls and I'm passing values of these controls using %Bind% syntax:



<asp:DetailsView ID="dvCity" runat="server" AutoGenerateRows="False" DataKeyNames="Id"
DataSourceID="sdsCity" DefaultMode="Insert" OnItemInserted="dvCity_ItemInserted">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True"
SortExpression="Id" Visible="False" />
<asp:TemplateField HeaderText="Name">
<InsertItemTemplate>
<asp:TextBox ID="txbName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txbName" SetFocusOnError="true"
Display="Dynamic" ErrorMessage="You must specify a non-blank value for Name.">*</asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RegionId" HeaderText="RegionId" SortExpression="RegionId"
Visible="False" />
<asp:TemplateField HeaderText="Region">
<InsertItemTemplate>
<asp:DropDownList ID="ddlRegion" runat="server" DataSourceID="sdsRegion" DataTextField="Name"
DataValueField="Id" SelectedValue='<%# Bind("RegionId") %>'>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>

DataSource for the DetailsView is the SqlDataSource which is using StoredProcedures to insert data into Database.


Some parts of business logic are located in the T-SQL code of the StoredProcedure and in case of any error I'm throwing exception from T-SQL using RAISE_ERROR method.

In the aspx.cs, OnItemInserted event of the DetailsView I've implemented following code for exception processing:

protected void dvCity_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
if (e.Exception != null)
throw e.Exception;
else
Response.Redirect("City.aspx");
}

When there is no error during StoredProcedure execution everything is works fine.
When my StoredProcedure raises any exception and this exception was handled by my handler user sees the AJAX popup and clicks OK.

Then popup closes, user edits values in DetailsView controls, clicks Save again BUT I got another exception saying that ((TextBox)dvCity.FindControl("txtName")) is NULL. The same is for DropDownList.


It seems to me that DetailsView loses databinding after an exception occurs during Insert/Update operation.
<b>Does anyone can help me how to handle or re-throw exception without DetailsView unbind?</b>

http://www.jetideas.com
QuestionTracing Pin
Priya S5-Sep-07 22:20
Priya S5-Sep-07 22:20 
AnswerRe: Tracing Pin
Parwej Ahamad5-Sep-07 22:39
professionalParwej Ahamad5-Sep-07 22:39 
GeneralRe: Tracing Pin
Priya S6-Sep-07 1:18
Priya S6-Sep-07 1:18 
AnswerRe: Tracing Pin
Sandeep Akhare5-Sep-07 23:48
Sandeep Akhare5-Sep-07 23:48 
GeneralRe: Tracing Pin
Priya S6-Sep-07 1:17
Priya S6-Sep-07 1:17 
GeneralRe: Tracing Pin
Sandeep Akhare6-Sep-07 1:50
Sandeep Akhare6-Sep-07 1:50 
AnswerRe: Tracing Pin
Shujaat Ullah Khan6-Sep-07 0:12
Shujaat Ullah Khan6-Sep-07 0:12 
GeneralRe: Tracing Pin
Priya S6-Sep-07 1:16
Priya S6-Sep-07 1:16 
GeneralRe: Tracing Pin
Shujaat Ullah Khan6-Sep-07 1:44
Shujaat Ullah Khan6-Sep-07 1:44 
QuestionASP 2.0 Deployment Pin
pksno15-Sep-07 22:04
pksno15-Sep-07 22:04 
QuestionHow can I access a textbox in an insertItemTemplate in a formview control. Pin
Big Ralph5-Sep-07 21:35
Big Ralph5-Sep-07 21:35 
AnswerRe: How can I access a textbox in an insertItemTemplate in a formview control. Pin
Ahmad Adnan5-Sep-07 23:14
Ahmad Adnan5-Sep-07 23:14 
GeneralRe: How can I access a textbox in an insertItemTemplate in a formview control. Pin
Big Ralph5-Sep-07 23:35
Big Ralph5-Sep-07 23:35 
Questionproblem when creating excel from a web page Pin
S Palip5-Sep-07 21:18
S Palip5-Sep-07 21:18 
AnswerRe: problem when creating excel from a web page Pin
Shujaat Ullah Khan6-Sep-07 0:47
Shujaat Ullah Khan6-Sep-07 0:47 
QuestionWhere to write VB Script file in ASP.Net 2.0 Pin
Priya_20075-Sep-07 21:17
Priya_20075-Sep-07 21:17 
AnswerRe: Where to write VB Script file in ASP.Net 2.0 Pin
Imran Khan Pathan5-Sep-07 23:08
Imran Khan Pathan5-Sep-07 23:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.