嵌套更新面板问题
我有一个嵌套的更新面板 像这样的
<asp:UpdatePanel ID="DetailsUpdatePanel" runat="server" Visible="false" UpdateMode="Conditional" >
<ContentTemplate>
<div><ajaxToolkit:AsyncFileUpload runat="server" ID="BrochureUpload" Width="400px"
OnClientUploadError="BrochureuploadError"
OnClientUploadStarted="BrochureStartUpload"
OnClientUploadComplete="BrochureUploadComplete"
CompleteBackColor="Lime" UploaderStyle="Modern"
ErrorBackColor="Red" ClientIDMode="AutoID"
ThrobberID="Throbber"
UploadingBackColor="#66CCFF"
onuploadedcomplete="BrochureUpload_UploadedComplete"/>
<asp:Label ID="Label1" runat="server" Style="display: none">
<asp:Image runat="server" ID="Image1" ImageUrl="~/Images/uploading.gif" />
</asp:Label>
<asp:Label ID="brochurelblstatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label></div>
<div><asp:UpdatePanel runat="server" ID="child" UpdateMode="Conditional" >
<ContentTemplate>
<div>
<asp:GridView ID=GridView2" runat="server" AllowPaging="true" AutoGenerateColumns="false" CellPadding="0" CellSpacing="1" DataKeyNames="ArticleId">
<Columns>
<asp:BoundField DataField="ArticleId" HeaderText="ArticleId" ReadOnly="True" HeaderStyle-CssClass="td1" />
<asp:BoundField DataField="FileName" HeaderText="FileName" ReadOnly="True" HeaderStyle-CssClass="td2" />
<asp:TemplateField HeaderText="BrochureUrl">
<ItemTemplate>
<asp:HyperLink ID="lnkEPhoto" runat="server" BorderWidth="2px" NavigateUrl='<%# GetUrl(Eval("ArticleId"),Eval("FileName")) %>'
Target="_blank"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnRemove" runat="server" text="Delete" CommandName="Delete" CausesValidation="False" OnClientClick="DeleteOrNo()">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel></div>
</ContentTemplate>
</updatePanel>
CodeBehind:
protected void BrochureUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
if(BrochureUpload.HasFile)
{
if(BrochureUpload.PostedFile.ContentLength<=3670016 )
{
var brochurePath = MapPath("~/") + Path.GetFileName(e.filename);
BrochureUpload.SaveAs(brochurePath);
using (var dataContext = new NewsStandAloneDataContext(Config.StandaloneNewsConnectionString))
{
var brochure = new xxx
{
Id = Convert.ToInt32(GridView1.SelectedValue),
FileName = Path.GetFileName(e.filename),
RecordCreated = DateTime.Now
};
dataContext.xxx.InsertOnSubmit(brochure);
dataContext.SubmitChanges();
}
bindGridView();//I have code to bind gridview
Child.Update();
}
}
}
protected void bindBrochureGridView()
{
using (var dataContext = new NewsStandAloneDataContext(Config.StandaloneNewsConnectionString))
{
var brochureList = (from brochure in dataContext.xxx
where brochure.ArticleId == Convert.ToInt32(GridView2.SelectedValue)
select new ArcticleBrochure
{
ArticleId = brochure.ArticleId.ToString(),
FileName = brochure.FileName
}).ToList();
GridView1.DataSource = brochureList;
GridView1.DataBind();
}
}
当我上传文件时,我希望更新子更新面板中的giedview。但它不起作用任何想法??????
提前致谢
I am having a nested update panel
something like this
<asp:UpdatePanel ID="DetailsUpdatePanel" runat="server" Visible="false" UpdateMode="Conditional" >
<ContentTemplate>
<div><ajaxToolkit:AsyncFileUpload runat="server" ID="BrochureUpload" Width="400px"
OnClientUploadError="BrochureuploadError"
OnClientUploadStarted="BrochureStartUpload"
OnClientUploadComplete="BrochureUploadComplete"
CompleteBackColor="Lime" UploaderStyle="Modern"
ErrorBackColor="Red" ClientIDMode="AutoID"
ThrobberID="Throbber"
UploadingBackColor="#66CCFF"
onuploadedcomplete="BrochureUpload_UploadedComplete"/>
<asp:Label ID="Label1" runat="server" Style="display: none">
<asp:Image runat="server" ID="Image1" ImageUrl="~/Images/uploading.gif" />
</asp:Label>
<asp:Label ID="brochurelblstatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label></div>
<div><asp:UpdatePanel runat="server" ID="child" UpdateMode="Conditional" >
<ContentTemplate>
<div>
<asp:GridView ID=GridView2" runat="server" AllowPaging="true" AutoGenerateColumns="false" CellPadding="0" CellSpacing="1" DataKeyNames="ArticleId">
<Columns>
<asp:BoundField DataField="ArticleId" HeaderText="ArticleId" ReadOnly="True" HeaderStyle-CssClass="td1" />
<asp:BoundField DataField="FileName" HeaderText="FileName" ReadOnly="True" HeaderStyle-CssClass="td2" />
<asp:TemplateField HeaderText="BrochureUrl">
<ItemTemplate>
<asp:HyperLink ID="lnkEPhoto" runat="server" BorderWidth="2px" NavigateUrl='<%# GetUrl(Eval("ArticleId"),Eval("FileName")) %>'
Target="_blank"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnRemove" runat="server" text="Delete" CommandName="Delete" CausesValidation="False" OnClientClick="DeleteOrNo()">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel></div>
</ContentTemplate>
</updatePanel>
CodeBehind:
protected void BrochureUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
if(BrochureUpload.HasFile)
{
if(BrochureUpload.PostedFile.ContentLength<=3670016 )
{
var brochurePath = MapPath("~/") + Path.GetFileName(e.filename);
BrochureUpload.SaveAs(brochurePath);
using (var dataContext = new NewsStandAloneDataContext(Config.StandaloneNewsConnectionString))
{
var brochure = new xxx
{
Id = Convert.ToInt32(GridView1.SelectedValue),
FileName = Path.GetFileName(e.filename),
RecordCreated = DateTime.Now
};
dataContext.xxx.InsertOnSubmit(brochure);
dataContext.SubmitChanges();
}
bindGridView();//I have code to bind gridview
Child.Update();
}
}
}
protected void bindBrochureGridView()
{
using (var dataContext = new NewsStandAloneDataContext(Config.StandaloneNewsConnectionString))
{
var brochureList = (from brochure in dataContext.xxx
where brochure.ArticleId == Convert.ToInt32(GridView2.SelectedValue)
select new ArcticleBrochure
{
ArticleId = brochure.ArticleId.ToString(),
FileName = brochure.FileName
}).ToList();
GridView1.DataSource = brochureList;
GridView1.DataBind();
}
}
When I upload the file , I want the giedview which is in the child updatepanel to be updated .But it doesnt work Any ideas?????
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
BrochureUpload_UploadedComplete
事件中调用child.Update();
。Call
child.Update();
inBrochureUpload_UploadedComplete
event.文件上传完成后,调用包含gridview的
UpdatePanel
的Child.Update()
方法。您需要这样做,因为您设置了UpdateMode="Conditional"
在这种情况下,您必须在代码中手动更新它。When file upload is complete then call
Child.Update()
method ofUpdatePanel
which contain gridview. You need to do that because you setUpdateMode="Conditional"
in this case you have to manually update it in code.更新面板中的
ChildrenAsTriggers="True"
。ChildrenAsTriggers="True"
in your updatepanel.