出错情况
- 页面放Anthem.FileUpload,TextArea(Anthem.TextBox),Anthem.Button.用户先选择了一个文件(没有选择文件不存在后面的问题),然后再点击Button时,在点击事件里改变TextArea的Text值并设置UpdateAfterCallBack为true.callback失败,提示BADRESPONSE.
前台:
<anthem:FileUpload ID="FileUpload1" runat="server" />
<anthem:TextBox ID="TextBox1" runat="server" Height="56px" TextMode="MultiLine" Width="246px"></anthem:TextBox>
<anthem:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Anthem Upload Button" />
后台:
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "afdasdfas";
TextBox1.UpdateAfterCallBack = true;
} -
前台代码:
< table cellpadding ="0" cellspacing ="0" border ="0" >
< tr >
< td valign ="top" >
< anthem:LinkButton ID ="lkbtnUploadPhoto" runat ="server" Text ="上传头像" CssClass ="TabLink"
OnCommand ="lkbtnTab_Click" CommandArgument ="3" ></ anthem:LinkButton >
</ td >
< td valign ="top" >
< anthem:LinkButton ID ="lkbtnSignature" PreCallBackFunction ="ResetForms" runat ="server" Text ="个性签名" CssClass ="TabLink"
OnCommand ="lkbtnTab_Click" CommandArgument ="4" ></ anthem:LinkButton >
</ td >
</ tr >
</ table >
< anthem:MultiView ID ="MultiViewMenu" runat ="server" >
< anthem:View ID ="viewUploadPhoto" runat ="server" >
< table >
< tr >
< td style ="width: 211px" >
< asp:Label ID ="Label10" runat ="server" Text ="当前头像" ></ asp:Label >
</ td >
< td >
</ td >
</ tr >
< tr >
< td style ="width: 211px" >
< anthem:Image ID ="imgCurrentPhoto" runat ="server" /></ td >
< td >
</ td >
</ tr >
< tr >
< td style ="width: 211px" >
< asp:Label ID ="Label11" runat ="server" Text ="从电脑中选择一幅新头像照片" ></ asp:Label >
</ td >
< td >
< input type ="button" id ="btnSelectPhoto" onclick ="FileUpload_Click();" value ="选择" /></ td >
</ tr >
< tr >
< td rowspan ="5" style ="width: 211px" >
< anthem:Image ID ="imgUploadImage" runat ="server" /></ td >
< td >
< asp:FileUpload ID ="PhotoFileUpload" runat ="server" /></ td >
</ tr >
< tr >
< td style ="height: 21px" >
< anthem:TextBox ID ="txtSelectUrl" ReadOnly ="true" runat ="server" ></ anthem:TextBox >
</ td >
</ tr >
< tr >
< td >
</ td >
</ tr >
< tr >
< td style ="height: 21px" >
< anthem:Button ID ="btnUpload" runat ="server" Text ="确认上传" />
< anthem:Button ID ="btnUplaodCancel" runat ="server" Text ="放弃" /></ td >
</ tr >
< tr >
< td >
</ td >
</ tr >
< tr >
< td rowspan ="1" style ="width: 211px" >
</ td >
< td >
</ td >
</ tr >
< tr >
< td style ="width: 211px" >
< asp:Label ID ="Label12" runat ="server" Text ="从相册中选择一幅照片" ></ asp:Label >
</ td >
< td >
< anthem:Button ID ="btnSelectServerPhoto" runat ="server" Text ="选择" /></ td >
</ tr >
< tr >
< td rowspan ="4" style ="width: 211px" >
< anthem:Image ID ="imgPhoto" runat ="server" /></ td >
< td >
</ td >
</ tr >
< tr >
< td style ="height: 21px" >
< anthem:TextBox ID ="txtPhotoUrl" ReadOnly ="true" runat ="server" ></ anthem:TextBox ></ td >
</ tr >
< tr >
< td >
</ td >
</ tr >
< tr >
< td style ="height: 21px" >
< anthem:Button ID ="btnOnlineEdit" runat ="server" Text ="在线编辑" /></ td >
</ tr >
< tr >
< td rowspan ="1" style ="width: 211px" >
</ td >
< td style ="height: 21px" >
</ td >
</ tr >
</ table >
</ anthem:View >
< anthem:View ID ="viewSignature" runat ="server" >
< table >
< tr >
< td valign ="top" >
< asp:Label ID ="lblSignature" runat ="server" Text ="个性签名" ></ asp:Label >
</ td >
< td >
< anthem:TextBox ID ="txtSignature" TextMode ="multiLine" runat ="server" Height ="171px"
Width ="335px" ></ anthem:TextBox >
</ td >
</ tr >
</ table >
</ anthem:View >
</ anthem:MultiView >
< table >
< tr >
< td >
< anthem:Button ID ="btnUpdate" runat ="server" OnClick ="btnUpdate_Click" Text ="保存修改" />
</ td >
< td >
< anthem:Button ID ="btnCancel" runat ="server" OnClick ="btnCancel_Click" Text ="取消" />
</ td >
</ tr >
</ table >
后台代码:
1
Tab Link Event
#region Tab Link Event
2 /**//// <summary>
3 /// Navigates to the Tab
4 /// </summary>
5 /// <param name="sender">sender</param>
6 /// <param name="e">EventArgs</param>
7 protected void lkbtnTab_Click(object sender, CommandEventArgs e)
8 {
9 ActiveViewIndex = Convert.ToInt16(e.CommandArgument.ToString());
10 SetTabDefaultCss();
11 ShowViewByTabId(ActiveViewIndex);
12 MultiViewMenu.UpdateAfterCallBack = true;
13 }
14 #endregion
15
16 Custom Event #region Custom Event
17
18 /**//// <summary>
19 /// show view by tab id
20 /// </summary>
21 /// <param name="tabId">the tab id</param>
22 private void ShowViewByTabId(int tabId)
23 {
24 switch (tabId)
25 {
26 case 3:
27 MultiViewMenu.SetActiveView(viewUploadPhoto);
28 lkbtnIntroduction.CssClass = TabSelectedCssName;
29 //PhotoFileUpload.Style.Add("display", "none");
30 btnUpdate.ValidationGroup = "";
31 btnUpdate.PreCallBackFunction = string.Empty;
32 break;
33 case 4:
34 MultiViewMenu.SetActiveView(viewSignature);
35 lkbtnSignature.CssClass = TabSelectedCssName;
36 txtSignature.Text = CurrentUserOtherInfo.Signature;
37 btnUpdate.ValidationGroup = string.Empty;
38 btnUpdate.PreCallBackFunction = string.Empty;
39 break;
40 }
41 btnUpdate.UpdateAfterCallBack = true;
42 }
43
44 /**//// <summary>
45 /// set tab default css class.
46 /// </summary>
47 private void SetTabDefaultCss()
48 {;
49 lkbtnSignature.CssClass = TabDefaultCssName;
50 lkbtnUploadPhoto.CssClass = TabDefaultCssName;
51 }
52
53 #endregion
2 /**//// <summary>
3 /// Navigates to the Tab
4 /// </summary>
5 /// <param name="sender">sender</param>
6 /// <param name="e">EventArgs</param>
7 protected void lkbtnTab_Click(object sender, CommandEventArgs e)
8 {
9 ActiveViewIndex = Convert.ToInt16(e.CommandArgument.ToString());
10 SetTabDefaultCss();
11 ShowViewByTabId(ActiveViewIndex);
12 MultiViewMenu.UpdateAfterCallBack = true;
13 }
14 #endregion
15
16 Custom Event #region Custom Event
17
18 /**//// <summary>
19 /// show view by tab id
20 /// </summary>
21 /// <param name="tabId">the tab id</param>
22 private void ShowViewByTabId(int tabId)
23 {
24 switch (tabId)
25 {
26 case 3:
27 MultiViewMenu.SetActiveView(viewUploadPhoto);
28 lkbtnIntroduction.CssClass = TabSelectedCssName;
29 //PhotoFileUpload.Style.Add("display", "none");
30 btnUpdate.ValidationGroup = "";
31 btnUpdate.PreCallBackFunction = string.Empty;
32 break;
33 case 4:
34 MultiViewMenu.SetActiveView(viewSignature);
35 lkbtnSignature.CssClass = TabSelectedCssName;
36 txtSignature.Text = CurrentUserOtherInfo.Signature;
37 btnUpdate.ValidationGroup = string.Empty;
38 btnUpdate.PreCallBackFunction = string.Empty;
39 break;
40 }
41 btnUpdate.UpdateAfterCallBack = true;
42 }
43
44 /**//// <summary>
45 /// set tab default css class.
46 /// </summary>
47 private void SetTabDefaultCss()
48 {;
49 lkbtnSignature.CssClass = TabDefaultCssName;
50 lkbtnUploadPhoto.CssClass = TabDefaultCssName;
51 }
52
53 #endregion
目前针对以上两种情况,我的解决办法是添加Button的 PreCallBackFunction="ResetForms"(红色部分)
function
ResetForms()
{
var fileUpload = document.getElementById("<%=PhotoFileUpload.ClientID %>");
if(fileUpload!=null && fileUpload.value!="")
{
document.forms[0].reset();
}
}
{
var fileUpload = document.getElementById("<%=PhotoFileUpload.ClientID %>");
if(fileUpload!=null && fileUpload.value!="")
{
document.forms[0].reset();
}
}
其实就是刷新form.不知道还有没有更好的解决办法.