本文介绍了Ajax Modal弹出扩展器中的fileupload控件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Datagrid控件,它显示ID,图像.当我单击编辑"按钮时,有一个按钮,单击后我想打开一个模式弹出扩展程序,该扩展程序将分配给包含文件上传控件,确定"和取消"按钮的面板.问题是当我按下OK按钮的button_click事件时,我无法在FileUpload控件内找到文件.
这是我的aspx页面代码:
I have a Datagrid control which displays Id, Image. When I am clicking on edit button a button is there and after click that i want to open a modal popup extender which will be assigned to a panel that contains a fileupload control, ok and cancel button. The problem is when I press the ok button the button_click event I am not able to find the file inside the FileUpload control.
Here is my aspx page code:
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<triggers>
<asp:AsyncPostBackTrigger ControlID="dgnews" />
</triggers>
<contenttemplate>
<asp:DataGrid ID="dgnews" runat="server" AutoGenerateColumns="false"
oncancelcommand="dgnews_cancel" ondeletecommand="dgnews_delete"
oneditcommand="dgnews_edit" onpageindexchanged="dgnews_PageIndexChanged"
onupdatecommand="dgnews_update" Width="715px" AllowPaging="true"
AllowSorting="true" DataKeyField="res_id" PageSize="10"
onitemdatabound="dgnews_ItemDataBound" >
<pagerstyle horizontalalign="Center" mode="NumericPages">
Position="TopAndBottom"/>
<columns>
<asp:BoundColumn DataField="res_id" Visible="false" HeaderText="">
<asp:TemplateColumn HeaderText="Image">
<itemtemplate>
<ul style="padding-removed15px;">
<a href="#"><img id="imgSmall" src=''<%# DataBinder.Eval(Container, "DataItem.res_image") %>'' alt="Gallery Image" width="50" height="50" /></a>
</ul>
</itemtemplate>
<edititemtemplate>
<asp:Button ID="aaa" Text="Select Images" runat="server"/>
<cc1:ModalPopupExtender BackgroundCssClass="modalBackground"
CancelControlID="Button2" runat="server" PopupControlID="picuploader" ID="ModalPopupExtender1"
TargetControlID="aaa" />
<asp:Panel ID="picuploader" runat="server" CssClass="modalPopup" DefaultButton="Button1" Style="display:none;">
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</triggers>
<contenttemplate>
<table>
<tr>
<td>
<asp:Image Width="50px" Height="50px" ID="Image1" runat="server" /></td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" /></td>
</tr>
<tr>
<td>
<asp:Image Width="50px" Height="50px" ID="Image2" runat="server" /></td>
<td>
<asp:FileUpload ID="FileUpload2" runat="server" /></td>
</tr>
<tr>
<td>
<asp:Image ID="Image3" runat="server" Width="50px" Height="50px" /></td>
<td>
<asp:FileUpload ID="FileUpload3" runat="server" /></td>
</tr>
<tr>
<td>
<asp:Image ID="Image4" runat="server" Width="50px" Height="50px"/></td>
<td>
<asp:FileUpload ID="FileUpload4" runat="server" /></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="Button1" runat="server" Text="ok" OnClick="UploadPic" />
<asp:Button ID="Button2" runat="server" Text="cancel" /></td>
</tr>
</table>
</contenttemplate>
</edititemtemplate>
<asp:EditCommandColumn CancelText="Cancel" EditText="Edit" HeaderText="Modify" UpdateText="Update"/>
<asp:ButtonColumn CommandName="Delete" Text="Delete" HeaderText="Remove"/>
</columns>
</pagerstyle></contenttemplate>
和cs如下:
and cs is as follows:
ClsCommon cls = new ClsCommon();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
BindGrid();
}
}
protected void BindGrid()
{
}
protected void dgnews_cancel(object source, DataGridCommandEventArgs e)
{
dgnews.EditItemIndex = -1;
BindGrid();
}
protected void dgnews_delete(object source, DataGridCommandEventArgs e)
{
try
{
}
catch (Exception ex)
{
}
}
protected void dgnews_edit(object source, DataGridCommandEventArgs e)
{
dgnews.EditItemIndex = e.Item.ItemIndex;
BindGrid();
Session["ID"] = dgnews.DataKeys[e.Item.ItemIndex];
}
protected void dgnews_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
dgnews.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
protected void dgnews_update(object source, DataGridCommandEventArgs e)
{
}
protected void UploadPic(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
string[] words = FileUpload1.FileName.Split(''.'');
string d_name = words[1];
HttpContext.Current.Session["SessionKey"] = System.Guid.NewGuid().ToString() + "." + d_name;
cls.UpdateData("_res", new string[] { "res_image" }, new string[] { Session["SessionKey"].ToString() }, "where res_id=''" + Session["ID"].ToString() + "''", "Updated Image1", this.Page);
if (FileUpload1.PostedFile.FileName.Length > 0)
{
string imgName = Session["SessionKey"].ToString();
string imgPath = "../images/Restaurant/" + imgName;
FileUpload1.SaveAs(Server.MapPath(imgPath));
}
}
if (FileUpload2.PostedFile != null)
{
string[] words = FileUpload2.FileName.Split(''.'');
string d_name = words[1];
HttpContext.Current.Session["SessionKey"] = System.Guid.NewGuid().ToString() + "." + d_name;
cls.UpdateData("_res", new string[] { "res_image2" }, new string[] { Session["SessionKey"].ToString() }, "where res_id=''" + Session["ID"].ToString() + "''", "Updated Image2", this.Page);
if (FileUpload2.PostedFile.FileName.Length > 0)
{
string imgName = "2" + Session["SessionKey"].ToString();
string imgPath = "../images/Restaurant/" + imgName;
FileUpload2.SaveAs(Server.MapPath(imgPath));
}
}
if (FileUpload3.PostedFile != null)
{
string[] words = FileUpload3.FileName.Split(''.'');
string d_name = words[1];
HttpContext.Current.Session["SessionKey"] = System.Guid.NewGuid().ToString() + "." + d_name;
cls.UpdateData("_res", new string[] { "res_image3" }, new string[] { Session["SessionKey"].ToString() }, "where res_id=''" + Session["ID"].ToString() + "''", "Updated Image3", this.Page);
if (FileUpload3.PostedFile.FileName.Length > 0)
{
string imgName = "3" + Session["SessionKey"].ToString();
string imgPath = "../images/Restaurant/" + imgName;
FileUpload3.SaveAs(Server.MapPath(imgPath));
}
}
if (FileUpload4.PostedFile != null)
{
string[] words = FileUpload4.FileName.Split(''.'');
string d_name = words[1];
HttpContext.Current.Session["SessionKey"] = System.Guid.NewGuid().ToString() + "." + d_name;
cls.UpdateData("_res", new string[] { "res_image4" }, new string[] { Session["SessionKey"].ToString() }, "where res_id=''" + Session["ID"].ToString() + "''", "Updated Image4", this.Page);
if (FileUpload4.PostedFile.FileName.Length > 0)
{
string imgName = "4" + Session["SessionKey"].ToString();
string imgPath = "../images/Restaurant/" + imgName;
FileUpload4.SaveAs(Server.MapPath(imgPath));
}
}
}
protected void dgnews_ItemDataBound(object sender, DataGridItemEventArgs e)
{
ListItemType listItemType = e.Item.ItemType;
if ((listItemType == ListItemType.EditItem) || (listItemType == ListItemType.Item))
{
Button imageButton = (Button)e.Item.FindControl("aaa");
if (imageButton != null)
{
UpdatePanel upanel = (UpdatePanel)e.Item.FindControl("UpdatePanel2");
upanel.Update();
Image1.ImageUrl = cls.FetchSinglevalue("select res_image from _res where res_id=''" + Session["ID"].ToString() + "''");
Image2.ImageUrl = cls.FetchSinglevalue("select res_image2 from _res where res_id=''" + Session["ID"].ToString() + "''");
Image3.ImageUrl = cls.FetchSinglevalue("select res_image3 from _res where res_id=''" + Session["ID"].ToString() + "''");
Image4.ImageUrl = cls.FetchSinglevalue("select res_image4 from _res where res_id=''" + Session["ID"].ToString() + "''");
}
}
}
推荐答案
<asp:PostBackTrigger ControlID="" />
这篇关于Ajax Modal弹出扩展器中的fileupload控件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!