Reputation: 3360
i have file upload control in FormView and that FormView is inside update panel when i try to update FormView everything works but image path from fileupload don't save after GridView1 rowcommand please help me...
page.aspx
<asp:UpdatePanel ID="upnl1" runat="server">
<ContentTemplate>
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" Width="20px">
<InsertItemTemplate>
<table>
<tr>
<td style="border-style: dashed dashed dashed none; dashedborder-style: none dashed none dashed;
border-width: thin; border-color: #000000;">
<asp:Label ID="Label14" runat="server" Text="user" BorderStyle="None"></asp:Label>
</td>
<td style="border-style: dashed none dashed none; border-width: thin; border-color: #000000;">
<uc1:Employee ID="UCEmployee" runat="server" />
</td>
<td style="border-style: dashed none dashed none; border-width: thin; border-color: #000000;">
<asp:Label ID="Label15" runat="server" Text="percent"></asp:Label>
</td>
<td style="border-style: dashed none dashed dashed; border-width: thin; border-color: #000000;">
<asp:TextBox ID="txtPartnership" runat="server" Width="60px"></asp:TextBox>
<asp:ImageButton ID="imgAddPersonel" runat="server" ImageUrl="~/App_Themes/images/icons/add.gif"
OnClick="imgAddPersonel_Click" />
</td>
</tr>
<tr>
<td style="border-style: none dashed dashed dashed; border-width: thin; border-color: #000000;"
colspan="4">
<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand">
</asp:GridView>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label20" runat="server" Text="attachment" ></asp:Label>
</td>
<td colspan="3">
<asp:FileUpload ID="FileUpload1" runat="server"/>
</td>
</tr>
</table>
</InsertItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" />
</ItemTemplate>
</asp:FormView>
.cs file
protected void imgAddPersonel_Click(object sender, ImageClickEventArgs e)
{
entity.EmployeeId = lovid;
entity.Partnership = Partnership;
entity.EmployeeFullName = USEmployee.Des;
Listentity.Add(entity);
HttpContext.Current.Session["Listentity"] = Listentity;
datagridbind(ref gd);
USEmployee.LOVId = null;
USEmployee.Des = "";
txtPartnership.Text = "";
USEmployee.Focus();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete1")
{
GridView gd = ((GridView)FormView1.FindControl("GridView1"));
int rowindex = int.Parse(e.CommandArgument.ToString());
int employeeid = (int)gd.DataKeys[rowindex]["EmployeeId"];
Listentity = (List<SuggestionEmployee>)Session["Listentity"];
Listentity.RemoveAt(rowindex);
Session["Listentity"] = Listentity;
datagridbind(ref gd);
}
}
protected void FormView1_DataBound(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Insert)
{
ImageButton lb = (ImageButton)FormView1.FindControl("imgAddPersonel");
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb);
}
}
Upvotes: 0
Views: 866
Reputation: 1051
EXPLANATION
This is the issue which normally occurs with Fileupload
control. Your FileUpload
control will not have the image path because your file upload control is in the UpdatePanel
.
When you run the program your UpdatePanel
will send request to the server and that request will be send to the ajax
therefor file upload control will not triggered and not work as expected.
ANSWER
You need to remove your FileUpload
control and place it out side the UpdatePanel
.
Then it will work as expected. I hope this information will be useful to you.
Have a great day.!
Upvotes: 1