ラベル updatepanel の投稿を表示しています。 すべての投稿を表示
ラベル updatepanel の投稿を表示しています。 すべての投稿を表示

2012年3月28日水曜日

Reset Controls inside an UpdatePanel

Is there an easy way to reset all controls within an updatepanel without having to reload the page? Or can I reload the page without using Response.Redirect or Server.Transfer? My page has 3 updatepanels.

Pls Define "Reset".


Remove all data in the controls.


Hi,

Thank you for your post.

I think it is easy! Do you remeber the reset HTML contorl?

The contorl reset the whole form Elements to original value.

Just add this:

<input id="Reset1" type="reset" value="reset" />

If you don't want display it,just hidden it and fire the click event of it in javascript.

If you have further question, let me know.

Best Regards,


Thanks

Resetting Scroll Position on AJAX partial postbacks

I'm sure someone has seen this one before:

    I have a grid inside an UpdatePanel displaying data that requires users to scroll to see the last couple of rows

    When a user selects a row in the grid, and AJAX post fires and displays data at the top of the page, but the scroll position is maintained and the user is required to scroll up to to the top of the page manually.

I need to reset the scroll position to 0,0 when a record is selected in my grid. If anyone can shed some light on this one I would greatly appreciate it.

Thanks

PS

Please see my post here:

http://forums.asp.net/t/1196152.aspx


Thank you - perfect solution, and so little code. I knew it wouldn't take much.

Resized image wont show in UpdatePanel

Hello,

I have a problem with a code where I want to resize an image in a Update Panel but when I fire up my site, I get this error in a message box:

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Details: Error parsing near '???JFIF'.

This is the code of the aspx page where the subs are called to resize and show the image (The formview is in a UpdatePanel):

1 <asp:FormView ID="DetailsFormView" runat="server" DataSourceID="DetailsFormSource">
2 <ItemTemplate>
3 <table style="vertical-align: top; text-align: left; width: 100%;">
4 <tr>
5 <td style="width: 150px; font-weight: bold;">
6 Initials:</td>
7 <td style="width: 278px">
8 <asp:Label ID="InitialerLabel" runat="server" Text='<%# Bind("Initialer")%>'></asp:Label></td>
9 <td rowspan="14" style="width: 188px">
10<%
11 ' make sure Nothing has gone to the client
12 Response.Clear()
13
14
15 If SearchGridView.SelectedValue = "" Then
16
17 Call sendError()
18
19 Else
20 If File.Exists(Server.MapPath("images/foto/" & SearchGridView.SelectedValue & ".jpg")) Then
21 Call sendFile()
22 Else
23 Call sendError()
24 End If
25
26 End If
27
28 Response.End()
29%>30 <asp:Image ID="EmpImg" runat="server" />
31 </td>
32 </tr>
33 <tr>
34 <td style="width: 150px; font-weight: bold;">
35 Full Name:</td>
36 <td style="width: 278px">
37 <asp:Label ID="FornavnLabel" runat="server" Text='<%# Bind("Fornavn")%>'></asp:Label>
38 <asp:Label ID="EfternavnLabel" runat="server" Text='<%# Bind("Efternavn")%>'></asp:Label></td>
39 </tr>
40 <tr>
41 <td style="width: 150px; font-weight: bold;">
42 Employee Nr.:
43 </td>
44 <td style="width: 278px">
45 <asp:Label ID="MedarbnrLabel" runat="server" Text='<%# Bind("Medarbnr")%>'></asp:Label></td>
46 </tr>
47 <tr>
48 <td style="width: 150px; font-weight: bold;">
49 Department code:</td>
50 <td style="width: 278px">
51 <asp:Label ID="afdelingskodeLabel" runat="server" Text='<%# Bind("afdelingskode")%>'>
52 </asp:Label></td>
53 </tr>
54 <tr>
55 <td style="width: 150px; font-weight: bold;">
56 Private address:</td>
57 <td style="width: 278px">
58 <asp:Label ID="padresseLabel" runat="server" Text='<%# Bind("padresse")%>'></asp:Label>,
59 <asp:Label ID="ppostnrLabel" runat="server" Text='<%# Bind("ppostnr")%>'></asp:Label>
60 <asp:Label ID="Bynavn" runat="server" Text='<%# Bind("Bynavn")%>'></asp:Label></td>
61 </tr>
62 <tr>
63 <td style="width: 150px; font-weight: bold;">
64 Private phone:</td>
65 <td style="width: 278px">
66 <asp:Label ID="ptelefonLabel" runat="server" Text='<%# Bind("ptelefon")%>'></asp:Label></td>
67 </tr>
68 <tr>
69 <td style="width: 150px; font-weight: bold;">
70 Private cellphone:</td>
71 <td style="width: 278px">
72 <asp:Label ID="pmobilLabel" runat="server" Text='<%# Bind("pmobil")%>'></asp:Label></td>
73 </tr>
74 <tr>
75 <td style="width: 150px; font-weight: bold;">
76 Phone:</td>
77 <td style="width: 278px">
78 <asp:Label ID="telefonLabel" runat="server" Text='<%# Bind("telefon")%>'></asp:Label></td>
79 </tr>
80 <tr>
81 <td style="width: 150px; font-weight: bold;">
82 Cellphone / Shortnr:</td>
83 <td style="width: 278px">
84 <asp:Label ID="mobil1Label" runat="server" Text='<%# Bind("mobil1")%>'></asp:Label>
85 /
86 <asp:Label ID="mobil2Label" runat="server" Text='<%# Bind("mobil2")%>'></asp:Label></td>
87 </tr>
88 <tr>
89 <td style="width: 150px; font-weight: bold;">
90 Mail address:
91 </td>
92 <td style="width: 278px">
93 <asp:Label ID="mailLabel" runat="server" Text='<%# Bind("mail")%>'></asp:Label>@dotnet.itags.org.***.com</td>
94 </tr>
95 <tr>
96 <td style="width: 150px; font-weight: bold;">
97 Private mail:</td>
98 <td style="width: 278px">
99 <asp:Label ID="pmailLabel" runat="server" Text='<%# Bind("pmail")%>'></asp:Label></td>
100 </tr>
101 <tr>
102 <td style="width: 150px; font-weight: bold;">
103 Based:
104 </td>
105 <td style="width: 278px">
106 <asp:Label ID="hjemh?rendeLabel" runat="server" Text='<%# Bind("hjemh?rende")%>'>
107 </asp:Label></td>
108 </tr>
109 <tr>
110 <td style="width: 150px; font-weight: bold;">
111 Position:</td>
112 <td style="width: 278px">
113 <asp:Label ID="StillingLabel" runat="server" Text='<%# Bind("Stilling")%>'></asp:Label></td>
114 </tr>
115 <tr>
116 <td style="width: 150px; font-weight: bold;">
117 Vehicle nr.:</td>
118 <td style="width: 278px">
119 <asp:Label ID="vognnrLabel" runat="server" Text='<%# Bind("vognnr")%>'></asp:Label></td>
120 </tr>
121 </table>
122 </ItemTemplate>
123 </asp:FormView>
124

And this are the subs that is resizing the image:

 
1Function NewthumbSize(ByVal currentwidth,ByVal currentheight)
234' Calculate the Size of the New image56Dim tempMultiplierAs Double
78 If currentheight > currentwidthThen' portrait9 tempMultiplier = 200 / currentheight
10Else11 tempMultiplier = 200 / currentwidth
12End If
131415 Dim NewSizeAs New Size(CInt(currentwidth * tempMultiplier),CInt(currentheight * tempMultiplier))
1617Return NewSize
18End Function
192021 Public Sub sendFile()
2223' create New image and bitmap objects. Load the image file and put into a resized bitmap.24Dim gAs System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("images/foto/" & SearchGridView.SelectedValue &".jpg"))
25Dim thisFormat = g.RawFormat
2627Dim thumbSizeAs New Size
28 thumbSize = NewthumbSize(g.Width, g.Height)
2930Dim imgOutputAs New Bitmap(g, thumbSize.Width, thumbSize.Height)
3132' Set the contenttype3334 Response.ContentType ="image/jpeg"353637 imgOutput.Save(Response.OutputStream, thisFormat)' output to the user
3839 ' tidy up40 g.Dispose()
41 imgOutput.Dispose()
4243End Sub
4445 Public Sub sendError()
4647' if no height, width, src then output "error"48Dim imgOutputAs New Bitmap(120, 120, PixelFormat.Format24bppRgb)
49Dim gAs Graphics = Graphics.FromImage(imgOutput)' create a New graphic object from the above bmp50 g.Clear(Color.Yellow)' blank the image51 g.DrawString("ERROR!",New Font("verdana", 14, FontStyle.Bold), SystemBrushes.WindowText,New PointF(2, 2))
52' Set the contenttype53 Response.ContentType ="image/gif"5455' send the resized image to the viewer56 imgOutput.Save(Response.OutputStream, ImageFormat.Gif)' output to the user
5758 ' tidy up59 g.Dispose()
60 imgOutput.Dispose()
61End Sub

I search a bit on the the what the problem could be, and I didn't find enything than that Response.Write can't be used, but I didn't hear nothing about the others Response methods that I am using.

You can't inject that type of data into the response stream of a partial postback. It boils down to the exact same problem as using Response.Write.

If I were you, I'd change that to a regular image control with the ImageURL dynamically assigned through code similar to what you have. If the thumbnail already exists, your function can return the path/file to it. If not, it creates the thumbnail and then returns the path/file. If there's an error, it can return the path/file of that error GIF.


Hmm.. I thought about your idea but I don't want to have the images two times.

But I got the problem solved.

I made an file called Thumbnail.aspx and in it I wrote:

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Thumbnail.aspx.vb" Inherits="Thumbnail" ContentType="image/jpeg" %>

And in Tumbmail.aspx.vb I added this code:

Imports System
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
PartialClass Thumbnail
Inherits System.Web.UI.Page

Private PathToImageAs String ="images/foto/"Sub sendFile()
' create New image and bitmap objects. Load the image file and put into a resized bitmap.Dim gAs System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(PathToImage & Request("src")))
Dim thisFormat = g.RawFormat
Dim imgOutputAs New Bitmap(g, 177, 239)

' Set the contenttype Response.ContentType ="image/jpeg"' send the resized image to the viewer imgOutput.Save(Response.OutputStream, thisFormat)' output to the user

' tidy up g.Dispose() imgOutput.Dispose()End Sub

Sub sendError()

' create New image and bitmap objects. Load the image file and put into a resized bitmap.Dim gAs System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("images/noimage.jpg"))
Dim thisFormat = g.RawFormat
Dim imgOutputAs New Bitmap(g, 177, 239)

' Set the contenttype Response.ContentType ="image/jpeg"' send the resized image to the viewer imgOutput.Save(Response.OutputStream, thisFormat)' output to the user

' tidy up g.Dispose() imgOutput.Dispose()End Sub

Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load

' make sure Nothing has gone to the client Response.clear()If Request("src") ="" Then
Call sendError()

Else

If File.Exists(Server.MapPath("PathToImage & Request("src")))Then
Call sendFile()
Else
Call sendError()
End If

End If response.end()End Sub
End Class

And in my formview I added this to display the image:

<img src="http://pics.10026.com/?src=Thumbnail.aspx?src=<%# SearchGridView.SelectedValue %>.jpg" alt="" style="border: 0px" />

That works for me,

Respons.Redirect problem in UpdatePanel

I want to reload my page in respone to click of that is placed in UpdatePanel.

I used Response.Redirecrt(Request.URI.ToString()) , i want to reload my page for loading new user control into UpdatePanel in page load event mean that i only want to refresh update panel area by restarting page lifecycle.

but ASPAJAX respond with a response stream error.

what's the problem? and what can i do?

You can not useResponse.Writein Ajax framework because there is no?whole?page postback to?take?place.If you want to display some text in a web page,you can place a asp:Label in a web form and display a text in the Label.
Wish this can help you.
?
Response.Redirect can work in Ajax framework. Try to use asynchronous post back? through the trigger in asp:UpdatePanel. Here are some sample codes for your reference.
<div>
<asp:UpdatePanel ID="upnl" runat="server">
<ContentTemplate>
<asp:Button ID="btnRedirect" runat="server" Text="Redirect" OnClick="btnRedirect_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnRedirect" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div
Behind Code:
protected void btnRedirect_Click(object sender, EventArgs e)
{
????Response.Redirect("Default.aspx");
}
Wish this can help you.

You mean that i can't redirect to a new page in page postback and also i can't force current page lifecycle repeatation.


ooh my problem is complicated, my page redirect by a button that this button is placed in a usercontrol that this UC load dynamicaly.

mean when i wriet code fro updatepanel , i don't know about what is the name of button and button change in ech postback because UC change in each postback.


I have download new version of AJAX RC version and Response.redirect is working for me...


No,I don't mean you can not redirect to a new page in page postback in current web page lifecycle repeatation.If you have some operations similar to Response.Write,you?can?not?do?it?in?Ajax?framework?as?that in ASP.NET?2.0.If?you?load?a?user?control?dynamically?and?redirect?to?a?new?web?page,
it?should?work?in?Ajax?package.Can?you?post?some?codes?here?with?the?response?stream?error??This?will?help?us?to?fix?the?problem.
The codes I provided in my last post can work fine in framework through asynchronous post back in a asp:UpdatePanel.

Thanks jasoon for your help.

Error is:

Sys.WebForms.PageRequestParserErrorException: The message received from the server could not be parsed .Common cause for this error are when the response is modified by calls to Response.Write() , response filters , HttpModules , or server trace is enabled.

Details: Error parsing near ' <!DocTYPE HTML PUB'.

and code is link this:

i didn't useResponse.Write()orResponse.Write()and aslo my didn;t set anywhere traceing to true i only used some HttpModules in my projects.

but when ic call to Response.Redirect("") in server in button_Click of button , this error occur.

what is my fault.


Thanks jasoon for your help.

Error is:

Sys.WebForms.PageRequestParserErrorException: The message received from the server could not be parsed .Common cause for this error are when the response is modified by calls to Response.Write() , response filters , HttpModules , or server trace is enabled.

Details: Error parsing near ' <!DocTYPE HTML PUB'.

and code is like this:

http://forums.asp.net/thread/1508052.aspx

I didn't useResponse.Write()or response filters and aslo i didn't set trace to true anywhere , i only used some HttpModules in my projects.

but when i call to Response.Redirect("") in server in Click of button , this error occur.

i describing again that this button placed in an UpdatePanel (with default settings) and cuase UpdatePanel to refresh.

what is my fault?


I tried to place a asp:Button in the asp:UpdatePanel of a user control and redirect to a new web page.It worked fine.Do you try my codes in my earlier post? Does it work in your PC? Try to download the latest Ajax package from this website and check if it works - http://ajax.asp.net/default.aspx?tabid=47&subtabid=471
Try to check your web.config if it is the same as the following.(Ajax RC 1.0 web.config)
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
Wish this can help you.

Thanks a lot jasson.

Your help be completely and the best.

My fault be incorrect configuring the web.config , i ignore addingScriptModuleHTTPModule.

Best regards.


oh my god!

my previous problem is solved but new problem appear:

if i use Server.Transfer in place of Server.Response same error appear in my IE window.

what's the problem?


Hi, Does you mean that you can redirect to a new page in the same window.

I am now facing an annoying problem. The redirect can do inside updatepanel, but it will open a new window for each redirect. I expect that a new page can be loaded in the same window.

Could you pleas help me.

I had a post to describe the problem.

http://forums.asp.net/p/1134773/1809506.aspx#1809506


Hi, Does you mean that you can redirect to a new page in the same window.

I am now facing an annoying problem. The redirect can do inside updatepanel, but it will open a new window for each redirect. I expect that a new page can be loaded in the same window.

Could you pleas help me.

I had a post to describe the problem.

http://forums.asp.net/p/1134773/1809506.aspx#1809506

Response.Redirect

I have a button on updatePanel, wich has event handler and Response.Redirect in it.

It's not working.

Haw can i resolve this problem.

Thansk

Deykin:

I have a button on updatePanel, wich has event handler and Response.Redirect in it.

It's not working.

Haw can i resolve this problem.

Thansk

Updatepanel and response.redirect don't work together and they shouldn't either. If you are going to redirect the page to some where else then why even bother to use updatepanel on it for. Updatepanel's purpose is to do partial postback on the same page. Hope that helps.


Actually, Response.Redirect() is supposed to work just fine during async postbacks.

Make sure that you have the ScriptModule registered in your application's web.config file. If it's not, check out the web.config that got installled to your Program Files ASP.NET AJAX folder to see what it should look like.

Thanks,

Eilon


As I recall, someone had the same problem a while ago. It never worked unless ajax implemented it in its lastest version.

Hi

instead of using Response.Redirect try this:

ScriptManager.RegisterClientScriptBlock( lbEditDocument,typeof(LinkButton ),"TestBlock","window.open('"+ redirectUrl +"', '_top');",true );

HTH


I'm with Luis on this one. Response.Redirect has been working fine for me with the RC, and if there's some bug, I'd love to find out before RTM gets out the door.

We could use some more info here, like what exactly is happening when the button is clicked. (I guess it's not doing the redirect, but is it refreshing the page? Is it doing an async postback? What does the traffic look like when you use Fiddler or Nikhil's Web Development Helper?)

2012年3月26日月曜日

Response.Redirect and regular postbacks

I have an updatepanel that includes several controls, and I need to be able to do things such as export to outlook, export to excel and use fileupload controls.

To move those links outside of updatepanels would compromise my layout.

Is there anyway I can force a button to perform a classic postback if it's inside an update panel?

Thanks!Hmmm, interesting. Here's an idea. Could you have a button outside the UpdatePanel with the "visibility:hidden" style set (NOT Visible=False, btw), and then have a button inside the UpdatePanel who's onclick script is "onclick='realPostBackButton.click()". So basically when the user clicks the button inside the UpdatePanel it just triggers a trick outside of it.
thanks for the tip. i could do that. if that's the only workaround possible, then i suppose it isn't too painful.

I can't think of another way to do it, so we'll keep it our little secret. :)


My button is outside of the update pannel and I get errors trying to export to excel. It gives me the following error:

Control 'ctl00_contentPlaceHolder_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

I think this is because I am using a Master Page with the Ultrapanel. My source for exporting to excel is:

protected

void btnExportToExcel_Click(object sender,ImageClickEventArgs e)

{

Response.Clear();

Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

Response.Charset = "";

Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

GridView1.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

}

It fails on the RenderControl method. Any ideas?

Thanks,

Duncan


Just what the code says - the Gridview must be within a <form runat="server"> element, either in the MasterPage or in the ContentPanel.

So there is no way to export a gridview that is in an Atlas:UpdatePannel, because my understanding if exists there is will not be in a <form runat="server"> element. If you try to put the <form> element in the ContentPannel of the UpdatePannel then it will conflict with the one in the master page.


The one at the master page should be fine. Something else must be causing the problem - is the ContentPlaceHolder in the Master Page not within the form tag?

Note the SampleWebsite that's included wiht the Toolkit (DefaultMaster.master) has a form tag and the GridView's in the sample pages work correctly.


I ended up using the Interop.Excel dll to export to excel and it worked.

I couldn't get my old method to work but it doesn't appear that it was an ATLAS issue. To get rid of that particular error I had add the following override.

public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for the

}


I am getting 'Unknown Error' and no export. What is the deal?. Is it possible to use Atlas and export to Excel?
Because AJAX is not doing a full post I found that you cannot do an export to excel with Response.Write. What I had to do was save the file to the server, and then do a windows.open in my javascript OnClientClick funtion.

Response.Redirect and UpdatePanel Problem Again

I can't figure out if I'm doing something wrong, it's just how it is, or it's a bug. If I create an UpdatePanel and place a button in it and then put Response.Redirect in the button's click event, everything works as I would expect and I'm redirected to the page I specified in the event. Now, if I drop a DataList inside the UpdatePanel and then put LinkButtons that have OnCommand and CommandArguement properties inside the DataList's ItemTemplate, response.redirect won't work for those LinkButtons. It just clears the datagrid and remains on the same page.

I've read everything I can find about people having the same problems but everything I read doesn't address buttons inside a DataList. Normal buttons in the UpdatePanel work for me. I'm using Ajax 1.0 RC.

Strange. Could you share your code?

Here's what I tried, and it works fine:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void item_command(object sender, DataListCommandEventArgs e) { Response.Redirect("http://ajax.asp.net"); } protected void Page_Load(object sender, EventArgs e) { list.DataSource = new string [] { "one", "two", "three" }; list.DataBind(); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head ID="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="sm1" runat="server" /> <asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:DataList ID="list" runat="server" OnItemCommand="item_command"> <ItemTemplate> <asp:LinkButton ID="button" runat="server" Text="<%# Container.DataItem%>" CommandName="redirect" /> </ItemTemplate> </asp:DataList> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

I need to get the CommandArgument from the LinkButton, set it to a session variable and then redirect. Here is an example of my code.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:datalist id="MyList" runat="server" EnableViewState="False" RepeatColumns="4">
<ItemTemplate>
<asp:LinkButton ID="MyLinkButton" runat="server" EnableViewState="FALSE" OnCommand="My_Command" CommandArgument='<%# Eval("MyID") %>'><%# Eval("MyName") %>
</asp:LinkButton>
</ItemTemplate>
</asp:datalist>
</ContentTemplate>
</asp:UpdatePanel>
Public Sub My_Command(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.CommandEventArgs) Session("MyID") = e.CommandArgument Response.Redirect("MyDetail.aspx",False)End Sub
 
Thanks!

I haven't tried this yet, but I notice you're passing False as the second argument to Response.Redirect()... does it make a difference if you change that to true? (Or simply drop it as in my example?)

I've tried it all three ways with the same result.


I tried the following code and it seems to work for me too. Have you used Fiddler on any other trace tool to chaeck what the response is from the server?

<%@. Page Language="VB" AutoEventWireup="true" %><script runat="server"> Protected Sub LinkButton1_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs) Session("MyID") = e.CommandArgument Response.Redirect("Default2.aspx") End Sub</script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" />   <asp:UpdatePanel ID="UpdatePanel1" runat="server" EnableViewState="False"> <ContentTemplate> <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" EnableViewState="False" RepeatColumns="4"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("AddressID")%>' OnCommand="LinkButton1_Command" Text='<%# Eval("AddressLine1") + Eval("AddressLine2")%>'></asp:LinkButton> </ItemTemplate> </asp:DataList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString%>" SelectCommand="SELECT TOP 100 Person.Address.* FROM Person.Address"></asp:SqlDataSource> </ContentTemplate> </asp:UpdatePanel>   </form></body></html>

I finally found the problem. In my codefile I have a sub that gets called that fills the datalist in the Page_Load procedure.

As an example:

If Not Page.IsPostBackThen
 'Do some stuff if this isn't a postback UpdateMyDataListEnd If
This worked for everything *except* clicking on the LinkButtons in the Datalist. So what I did was this and it now works for the LinkButtons as well.
 
If Not Page.IsPostBackThen
 'Do some stuff if this isn't a postback
Else UpdateMyDataListEnd If

Response.Redirect cant worked as expected inside UpdatePanel while placed in a ModalDialog

I placed a updatepanel in a modaldialog and placed a button inside the updatepanel. when clicked on the button, something needs to be done and if necessary, the button maybe call Response.Redirect(...) to force moveing to a new URL in the same Modaldialog.

I placed " <base target='_self' " /> inside the " <head> " of the page, and the Redirect can do as expected while the button is placed outside the updatepanel. but If the button is moved inside updatepanel, the 'Redirect(...)' will always open a new window, that's is unexpected.

I tried the client script, such as ' window.location.replace(...)' also, but it acts as above. even if I placed a <input type='button' onclick='window.location.replace(..)' /> inside the updatepanle.

Is this a bug of UpdatePanel? Because the objective can be done without updatepanel.

Could you please help me?

Thank you very much.

did you try Server.Transfer instead of Response.Redirect ??


Thanks!

I had tried Server.Transfer already yesterday. but a exception is popup.

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common casuses for this error are when the respons is modified by calls to Response.Write(), response, filters, HttpModules, or server trace is enabled. .....


hi i too faced the same problem i over came it bye writing the Response.Redirect("javascript:mypopfunction()");

in response.redirect write that jave script function call write u r window code in java script to pop up this worked finre for me u also try this it will work if not let me know ao that i may further help u ok byee ALL THE BEST

Vissu


Thank you.

I write client function as follow.

<script>
function MoveToURL(newurl)
{
window.location.replace(newurl);
}
</script>

Then respond to button click event on server-side as follow :

Response.Redirect("javascript:MoveToURL('Dialog2.aspx');");

But the problem still exists. Maybe I didnt catch your real idea. Could you please give a example.


hi pass the page name webform2.aspx as a parameter to function in java script

ieeee....

<script>
function MoveToURL(newurl)
{
var reportWin=window.open(newurl,"options",'resizable=yes,scrollbars=yes,width=780,height=650,left=150,top=50,status=yes')


}
</script>

Then respond to button click event on server-side as follow :

string myaspx="Dialog2.aspx'";

Response.Redirect("javascript:MoveToURL('"+myaspx+"')");

hope this helps...

Vissu


it functions as before. a new window is open unexpected.

it seems all the script executed from inside an updatepanel results in the same. despite of :

window.open

window.location

Response.Redirect


i doing the same thing i send but it is working fine for me i don't know why its not working for u any way try u will defnitly get answer for that ALL THE BEST

Vissu


The problem is that you're trying to do something that requires an HTTP response context to work, in a partial postback which does not return in an HTTP response.

Use something like this:

ScriptManager.RegisterStartupScript(this,this.GetType(),"redir","document.location = 'NewPage.aspx'",true);

hi this will work look at it

ScriptManager.RegisterStartupScript(this,this.GetType(),"EmpReports","javascript:ReportPage('" + PName +"')",true);

write this in C# Code

Vissu


this worked as above. the problem still exists.

Please note that the UpdatePanel is in a ModalDialog.

For the normal window, response.redirect can work correctly.

For the ModalDialog, if updatepanel is not used, the redirect can work correctly by adding <base target='_self' /> to <HEAD>. Once updatepanel is used in modaldialog, the redirect opens always a new window.


Without more much better solution, now I just use the following code:

Replace 'Response.Redirect' with a client script to show a new modal dialog from current dialog.

string script = "window.showModalDialog('Dialog2.aspx'); window.close();";
ScriptManager.RegisterStartupScript(this, this.GetType(), "OpenNewDialog", script, true);

this solution will launch too much dialog window. So I still sincerely hope someone can help me solving this problem ina better way.

Thanks.


You can't do Response.Write() while using an AJAX

See for more details..

http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx


I am using Response.Redirect, not Response.Write, and Response.Redirect can work correctly with an updatepanel inside a normal window. In this case, the new page can be loaded in the same window. Once Used with an updatepanel inside a modal dialog, the new page is loaded always in a newly opened window. The key difference is between normal window and modaldialog.


What you are trying to do is not possible with ModalPopup extender. The ModalPopup usually binds with an Asp Panel renders as Div (Not a Window). So playing with the url Response.Redirect, window.location will always opens a new page.

Response.Redirect doesnt work with UpdatePanel in Beta 1

I have a page with an update panel that contains a few buttons that need to be able to redirect to another page. The script manager is located on a master page.

Every time one of those buttons are clicked, i get one of two errors:

    If the button is inside of a gridview, i get this error:
    Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
    If the button is NOT inside of a gridview, i get this error:
    Sys.WebForms.PageRequestManagerParserErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 302

Here's a test aspx page that I set up:

1<%@dotnet.itags.org. Page Language="VB" title="Untitled Page" MasterPageFile="~/main.master" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>2<%@dotnet.itags.org. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Web.UI" TagPrefix="ajax" %>3<asp:Content ID="Content1" ContentPlaceHolderID="plhContent" Runat="Server">4 <ajax:UpdatePanel runat="server">5 <ContentTemplate>6 <asp:Label runat="server" ID="lblTime" /><br />7 <asp:Button runat="server" ID="btnRefresh" Text="Refresh" /><br />8 <asp:Button runat="server" ID="btnRedirect" Text="Redirect" /><br />9 <asp:LinkButton runat="server" ID="lnkRedirect" Text="ASP Linkbutton" /><br />10 <a href="http://www.google.com/" title="test redirect">HTML Hyperlink</a>11 </ContentTemplate>12 </ajax:UpdatePanel>13</asp:Content>
And here's the codebehind:
1PartialClass test2Inherits System.Web.UI.Page34Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load5 lbltime.Text = now()6End Sub78 Protected Sub btnRedirect_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles btnRedirect.Click9 Response.Redirect("http://www.google.com/",True)10End Sub1112 Protected Sub btnRefresh_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles btnRefresh.Click13 lblTime.Text = Now()14End Sub1516 Protected Sub lnkRedirect_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles lnkRedirect.Click17 Response.Redirect("http://www.google.com/",True)18End Sub19End Class


The LinkButton causes the same error, so it's not just limited to the button control. It looks like it affect anything that posts back to the server and causes a redirect.

Thanks for any help you can give me!

We found this out today too. The fix is to pass a location.href back to user.

ScriptManager.RegisterStartupScript(pnlYourUpdatePanel,this.GetType(),"redirectMe","location.href='blah.aspx';",true);

Sorry it is in C#... Hope this helps.


hello.

i've just built a sample project with the following code:

master page:

<%@. Master Language="VB" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<script runat="server"
</script
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:scriptmanager runat="server" ID="manager" />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>

page:

<%@. Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<script runat="Server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblTime.Text = Now()
End Sub

Protected Sub btnRedirect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRedirect.Click
Response.Redirect("http://www.google.com/", True)
End Sub

Protected Sub btnRefresh_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
lblTime.Text = Now()
End Sub

Protected Sub lnkRedirect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkRedirect.Click
Response.Redirect("http://www.google.com/", True)
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:updatePanel runat="server" id="panel">
<contenttemplate>
<asp:Label runat="server" ID="lblTime" /><br />
<asp:Button runat="server" ID="btnRefresh" Text="Refresh" /><br />
<asp:Button runat="server" ID="btnRedirect" Text="Redirect" /><br />
<asp:LinkButton runat="server" ID="lnkRedirect" Text="ASP Linkbutton" /><br />
<a href="http://links.10026.com/?link=http://www.google.com/" title="test redirect">HTML Hyperlink</a>
</contenttemplate>
</asp:updatePanel>
</asp:Content
everything is working here with the beta extensions. are you sure you've set up web.config correctly?


Luis,

When looking at the XMLHttpResponse google.com is being returned which is causing the parser error. Not sure how you are getting this to work with the Beta release?? Also, not sure how config would cause this?

Matt


hello.

well just recalled one problem i've seen before where the users updated the prefix but left it pointing to the old ctp dll which was still in the bin folder and it just blow everything apart. btw, here's what i'm getting back from the server side in response to a click over the redirect button (2nd one from the top):


22|pageRedirect||http://www.google.com/|


Luis Abreu:

everything is working here with the beta extensions. are you sure you've set up web.config correctly?

I think I do. I have a Microsoft.Web.Extensions assembly in the web.config. Is there aything else I need?

1<compilation debug="true" strict="false" explicit="true">2 <assemblies>3 <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>4 <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>5 <add assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>6 </assemblies>7</compilation>


Luis Abreu:

well just recalled one problem i've seen before where the users updated the prefix but left it pointing to the old ctp dll which was still in the bin folder and it just blow everything apart.

I did delete the old CTP DLL, and added the new assembly registration to the top of the page:

1<%@. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Web.UI" TagPrefix="ajax" %>2

hello again.

can you confirm the response you're getting back from the server? is it similar to the one i've shown before?


How do I access the server response information?

hello.

use fiddler. if you're using ie, you must create a site in IIS and then use the name of the machine (http://machinename/site). if you're using firefox, configure it so that it uses a local proxy (127.0.0.1 port 8888 if i'm not mistaken).


It is definitely in the config. Again... good call Luis... you are missing these values in your config and this should cure the problem.

<httpModules><add name="WebResourceCompression" type="Microsoft.Web.Handlers.WebResourceCompressionModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add name="ScriptModule" type="Microsoft.Web.UI.ScriptModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/></httpModules>
Thank Luis for that one. =)
P.S. That is under httpHandlers

That worked! You guys are awesome.


Thanks!


Thanks - Guys!

I was experiencing the same problem in Beta 2, which this solution apparently resolved that issue.


Hi Guys!

I Got the Same error in my current project. I cant redirect to another page from inside the UpdatePanel. Finally I saw this forum and got a wonder result and answer. Its really amazing and thanks a lot for u all guys..

rgds,

Senthil

Response.Redirect doesnt work when the button is inside an ajax updatepanel

Hello,

I am getting the following error whenever I click a button inside an ajax updatepanel and it tries to Response.Redirect from the code behind.

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Details: Error parsing near'

<!DOCTYPE html P'

I wasn't sure if it was my page not being correct or if it was something else. So I created two basic test pages test.aspx and test2.aspx. I click a button on text.aspx and it is supose to redirect to test2.aspx. This is a basic example giving the exact same error. So hopefully if I can get a resolution to this I could fix my real asp.net page. Thanks, Risso

Here is the test.aspx code:

<%

@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="test.aspx.cs"Inherits="test" %>

<%

@dotnet.itags.org.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"Namespace="System.Web.UI"TagPrefix="asp" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><linkhref="css/modaldialog.css"rel="stylesheet"type="text/css"/><title>Untitled Page</title>

</

head>

<

body><formid="form1"runat="server"><div><asp:ScriptManagerID="ScriptManager1"runat="server" ></asp:ScriptManager><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:ButtonID="Button1"runat="server"OnClick="Button1_Click2"Text="Button"/></ContentTemplate></asp:UpdatePanel></div></form>

</

body>

</

html>

HERE IS the Code behind code:

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclasstest : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedvoid Button1_Click2(object sender,EventArgs e)

{

Response.Redirect(

"~/test2.aspx");

}

}

HI.

Try to useServer.Transfer.


I did server.transfer shown below. It still gives the same error message. I put a breakpoint in the test2.aspx to see if it makes it to that pages_load event and it does, but the browser throws the exact same error message as listed in the first post. Any other ideas?

protectedvoid Button1_Click2(object sender,EventArgs e)

{

Server.Transfer("~/test2.aspx");

}


Hi, u must knwo that Response.Redirect and Server.Transfer work inside UpdatePanel.

can u share us the detail of the error that u have.


I tried your code and one of my own and it appears to be fine. Before you start beatin your head against the wall, try this...

This a must read from Eilon Lipton's Technical blog on Microsoft ASP.NET and ASP.NET AJAX when trying to solve PageRequestManagerParserErrorException errors!

http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx?CommentPosted=true#commentmessage A


Eilon Lipton's tips are great, I just add some more: Test "test2.aspx" for any invalid html markup, also test the response with fiddler.

Ok,

I found out were it is happening, but now I am not sure how to solve it since what I have to remove is also needed. I found that it was inside the web.config. I'm adding 2 httphandlers that were needed to fix other AJAX issues. I don't recall exactly what those issues were because this is a big application and it was a while back. I do remember these were needed to fix other ajax problems though. I do not want to remove these and have them break other ajax controls/tools. Anyone know a work around for this. I do know now that these httpHandlers are what is causing my Response.Redirect() issue in my updatepanel.

I removed the following lines from my web.config for it to work.

<

httpHandlers>

<

removeverb="*"path="*.asmx"/>

<

addverb="*"path="*.asmx"validate="false"type="Microsoft.Web.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<

addverb="GET,HEAD"path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"validate="false"/>

</

httpHandlers>

Risso


Shoot, I just realized those were needed for the Ajax to work in IE. And by me removing those lines from the web.config it just does a normal postback and not an asynchronous call. That is why it worked for me. So really nothing has changed. I am back to nothing on why the response.redirect() doesn't work. You guys mentioned that you took the code and were able to get the response.redirect() to work. I'm not sure what in my environment could be any different. I'm running this off of localhost and I do not have IIS running.

Yeah. Have you tried a new website as ajax supported web? I tried both an iis and casini version of the test. What version of vs are you running?


Aesop:

Yeah. Have you tried a new website as ajax supported web? I tried both an iis and casini version of the test. What version of vs are you running?

Agree, use vs to create a new "ASP.NET Ajax-Enabled Web Site" or "ASP.NET Ajax CTP-Enabled Web Site", and use the web.config of the new site as a template, so carefully migrateyourweb.config into the template.

You can get a template web.config also from a similar path:

C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025

C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Futures January CTP\v1.0.61025


Yes, I got it to work!! Thank you for your persistent responses. I did what you both recommended and started a new Ajax Application and pulled its web.config to compare to mine and went line by line with testing each line and found what I was missing. My web.config didn't have

<

httpModules>

<

addname="ScriptModule"type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

</

httpModules>

Risso


Hi Rissoman,

Thanks your post. I have the problem like you. I took 2 days to find why I always take the PageRequestManagerParserErrorException. Well, I am upgrading the website, and missing the <httpModules>

Thanks again,

HUH


Thanks to everyone who posted about this. You've just saved me a lot of time and effort! Thanks!


HI,

Thanks a ton .for that code..

regards

Delia Joe

Response.Redirect from UpdatePanel causes full refresh

I noticed that when I redirect to another page from within an update panel, the page fully refreshes (may be that's by design?).

How can I prevent this from happening?

Thanks.

you can not prevent this, this is the way any web sites works. When you say response.redirect, you are instructing the browser to make a fresh call to particular aspx page.


rmaiya:

you can not prevent this, this is the way any web sites works. When you say response.redirect, you are instructing the browser to make a fresh call to particular aspx page.

that is right.

If you are trying to only update the panel then try something like, updatePanel1.update();, or if you want to load a new page inside the panel try putting an iframe inside the panel


What is considered as best practice?

For example, if you click on the above links (such as "Learn", "Downloads", "Ajax"...) on this page, how do they ensure that that the header and footer elements of the page don't "blink"?


As they are different pages, I do want to do a response.redirect to keep the URL's friendly, but at the same time, I would like my header and other static elements not refresh each time. Do they use partial page caching to achieve this?

response.write and wizard

Hello!

I've been digging internet 2 days now...

Basically, i have a page with updatepanel on it. Inside, there's a wizard , with a button on the last step. This button finish the wizard - it process the whole data we have from user and it generates a file, which user should receive, with the ability to save it or open. It's easy - Response.Write. Of course it's a well known issue - ajax can't stand response.write. There are some ways to solve it , but it doesn't work for me. I've already registered it as PostbackControl, then as a AsyncControl. Added it to update's panel trigger's ( can't do it dynamically, but i did it otherwise).

Does anybody has any solution to my scenario?

I'm not sure I follow your scenario, are you trying to send the file to the user, or just data? If you're trying to get the user to be able to open/save the file, then the only way I can think of would be a redirect or transfer of the request. if it's juts data, then put a dummy asp:label in there and change its Text value.


i thought i made it clear :(

page->updatepanel->wizard->response.redirect . yes, i want to send FILE to the user.

Response.Write inside Updatepanel Beta 2

Hi,

I have a button inside a updatepanel, when the client click the button he can download a PDF. Everything works perfectly outside the update panel but not inside it. I got the next error message:

Sys.Webforms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error is when the response is modified by calls to Response.Write...

I really appreciate any help.

Thanks,

Jaime

My code:

PrivateSub ShowPdf(ByVal strPathAsString)

Response.ContentType =

"application/x-download"

Response.AddHeader(

"Content-Disposition","filename=YourPdf.pdf")

Response.WriteFile(strPath)

Response.End()

End Sub

<%@dotnet.itags.org.PageLanguage="VB"AutoEventWireup="false"CodeFile="Resultados.aspx.vb"Inherits="Resultados" %>

<%@dotnet.itags.org.RegisterAssembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Namespace="Microsoft.Web.UI"TagPrefix="asp" %>

<%

@dotnet.itags.org.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="AjaxToolKit" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

.............

<

asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><tablestyle="width: 840px"><tr><tdstyle="width: 762px; height: 153px;"><AjaxToolKit:RoundedCornersExtenderID="RoundedCornersExtender1"runat="server"TargetControlID="TitlePanel1"Radius="10"></AjaxToolKit:RoundedCornersExtender><AjaxToolKit:CollapsiblePanelExtenderID="CollapsiblePanelExtender1"runat="server"Collapsed="true"SuppressPostBack="false"TargetControlID="ContentPanel1"ExpandControlID="Panel1"CollapseControlID="Panel1"imageControlID="image1"ExpandedImage="~/images/collapse_blue.jpg"CollapsedImage="~/images/expand_blue.jpg"></AjaxToolKit:CollapsiblePanelExtender>............

<

asp:PanelID="ContentPanel1"runat="server"CssClass="collapsePanel"Height="0"Width="728px"><tablestyle="width: 728px"><tr><tdstyle="width: 93px; height: 4px"><asp:ButtonID="Button1A"runat="server"Font-Bold="True"Font-Size="X-Small"ForeColor="Crimson"Text="Get Your PDF"Width="224px"/></td>

Hi,

After a while I have found a workaround for the problem I posted, so I am posting this workaround here in case someone else have the same problem:

Basically I have include a second button (button2) outside the control panel. Once the first button (button1, the one inside the updatepanel) is clicked it fire the next javascript:

<input type="submit" name="Button1" value="Button" onclick="javascript:document.getElementById('button2').click() ;" id="Button1" /><br />

So button1 "clicks" button2 (that is the one outside the updatepanel) and this second button is the one that get the PDF file.

To include the javascript you just need to include the next line (in vb) in the "load" of the page:

button1.Attributes.Add(

"onclick","javascript:document.getElementById('button2').click() ;")

Now i am looking for a way to hidde button2 (notice that in order to click it you can not set visible to false).

Hope this can help someone.

Best,

Jaime

Restore position of a modal panel after postback

There is a modal panel which was created with the help of a modalPopupExtender. There is also an updatePanel and a GridView on it. Selecting a row in the GridView raises postback what sets the position of modal panel to default value (center of the screen). How to restore position at the moment of postback?

Hi,

According to your problem, I think you may keep the position of the modalPopup in two hiddenfileds outside UpdatePanelbefore postback, and set the popup's position to those values in hiddenFields inendRequest event handler.

For instance:

function beginRequestHandler()
{
$get("hfX").value = $find('behaviorIDOfModalPopup').get_X();
$get("hfY").value = $find('behaviorIDOfModalPopup').get_Y();
}

function endRequestHandler()
{
$find('behaviorIDOfModalPopup').set_X($get("hfX").value);
$find('behaviorIDOfModalPopup').set_Y($get("hfY").value);
}

Hope this helps.


Thanks,

There is one more solution:

function BeginRequest(sender, args) { var s = $get('Panel1').style.left; $find('ModalPopupExtender1').set_X(s.substring(0, s.length - 2)); s = $get('Panel1').style.top; $find('ModalPopupExtender1').set_Y(s.substring(0, s.length - 2)); }

Retaining GridView cell color on postback

I have a GridView in an UpdatePanel in which I use JavaScript to allow the user to change cell colors on the fly. It works great, until a postback occurs in which case, all of the user changes are lost. How do I maintain the cell colors after postback? I am trying to use a Save button to store the status of each cell to a database. Unfortunately, the cell colors are reset immediately, so even the save routine does not work correctly.

Thanks for any help you can provide,

Todd

Here is the script used to change the color of a cell when the user right-clicks on it:

<script type="text/javascript"><!-- /* script for changing the background color of the table cells based on the "Selection Mode" */ document.getElementById('ctl00_MainContentPlaceHolder_gvWafer').onmousemove = MouseMove; document.getElementById('ctl00_MainContentPlaceHolder_gvWafer').onmousedown = MouseMove; document.getElementById('ctl00_MainContentPlaceHolder_gvWafer').oncontextmenu = DontShowContext; document.getElementById('ctl00_MainContentPlaceHolder_gvWafer').onmouseup = MouseUp; // handle the MouseMove event for the GridView control function MouseMove(event) { // IE doesn't pass the event object, so we have to pass it manually if (event == null) event = window.event; /* only select table cells if the right mouse button is pressed and the underlying item is a 'TD' element (table data) */ if (event.button == 2 && event.srcElement.tagName == 'TD') { var cell=event.srcElement; var cellValue=cell.innerHTML; /* display the row and column indexes in the browser status bar */ window.status="row, column = " + cell.cellIndex + "," + cell.parentElement.rowIndex; /* determine which item in the Selection Mode drop down list box is selected */ switch(document.getElementById( 'ctl00_MainContentPlaceHolder_ddlSelectMode').getAttribute( 'selectedIndex')) { case 1: // available /* Don't allow cells marked as QC Samples to be marked Available */ if (cell.style.backgroundColor != '#996600') { // GREEN cell.style.backgroundColor='#00FF00'; } break; case 2: // picked /* Don't allow cells marked as QC Samples to be marked as Picked */ if (cell.style.backgroundColor != '#996600') { if (cellValue >= 20 || cellValue <= 200) { // GRAY cell.style.backgroundColor='#999999'; } else { // WHITE cell.style.backgroundColor='#FFFFFF'; } } break; case 3: // reserved /* Don't allow cells marked as either Picked or QC Samples to be marked as Reserved */ if (cell.style.backgroundColor != '#996600' && cell.style.backgroundColor != '#999999') { if (cellValue >= 20 || cellValue <= 200) { // PURPLE cell.style.backgroundColor='#9933CC'; } else { // WHITE cell.style.backgroundColor='#FFFFFF'; } } break; default: return; } } } /* clear the status bar data */ function MouseUp(event) { window.status = ""; } /* handle the ContextMenu event for the GridView control - Don't show the default context menu */ function DontShowContext(event) { return false; } if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); // --></script>

You are going to need to save these styles and reinitalize them on the callback of the UpdatePanel e.g.:

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_endRequest(EndRequestMethod);

prm.add_beginRequest(BeginRequestMethod);

...or you can add your logic to the server side. The problem is that you are rebinding the whole GridView and obviously client-side changes aren't persisted.

-Damien


Get the current PageRequestManager instane and

try to use beginRequest and endRequest


Thanks for both of your inputs. I don't know why I expected the JavaScript to make the changes to the GridView control. I forgot that the GridView control is rendered as a Table and that the JavaScript was simply modifying the Table. I actually took a little bit different route to solve the problem (I didn't see your replies until just a few minutes ago...had email notification turned off by mistake).

So, since the GridView is rendered as a Table and JavaScript cannot change GridView properties, I had to somehow track the changes that were made to the Table and propagate them to the GridView control.

I decided to create a TextBox control in which the JavaScript code would write the changes made to the cells (in the format "[row],[column]=[color]\n"). My VB code then parses out those changes and makes the corresponding change in the GridView control. I make the width and height of the TextBox zero so that it is not visible.

It may not be the best way to accomplish the task, but it is working. Since this is for an intranet application, and I have a ton more work to do, I am going to stick with it. The next time I run into a problem like this I will keep the other suggested solutions in mind.

Thanks,

Todd

Retrieve value from a dynamically created control inside an UpadetPanel

I would like to dynamically create some controls - tablecells, textboxes, and dropdownlists inside an AJAX UpdatePanel.
How would I retrieve the values that user enters into these controls in my vb.net code behind?
Can you please provide vb.net sample code ??

Here is my code:

'creates the textboxes - works fine

For i = 1 To intUnseatedGuestCount
Dim txtFirstName As New TextBox
txtFirstName.ID = "txtFirstName" + i.ToString
Me.tdNewSeatingCards.Controls.Add(txtFirstName)
Next

'code to retreive the values - produces an error message

Object reference not set to an instance of an object

For i = 1 To Me.hidNewSeatingCardCount.value
strTXTName = "txtFirstName" + i.ToString
Dim myTXT As TextBox = CType(Me.tdNewSeatingCards.FindControl("txtFirstName" + i.ToString), TextBox)
strTest += myTXT.Text + "<br>"
Next

Thank you for your help

You are creating controls dynamically, So on every postback (even in asynchronous postbacks ) you have to create it


OK Here is my code to recreate the controls:

For i = 1 To Me.hidNewSeatingCardCount.Value
Dim txtFirstName As TextBox = CType(Me.tdNewSeatingCards.FindControl("txtFirstName" + i.ToString), TextBox)
txtFirstName.ID = "txtFirstName" + i.ToString
Me.tdNewSeatingCards.Controls.Add(txtFirstName)
strTest += CType(Me.tdNewSeatingCards.FindControl("txtFirstName" + i.ToString), TextBox).Text
Next

There are no error messages, but I am not getting the values that the user enters into the textbox.

Thank you


Hi,

Thank you for your post!

You should place your recreate code in the init event.

The cause of the issue is viewstate process is finished before you recreate your controls!

If you have further questions,let me know!

Best Regards,

retrieve value from a dynamically created control

I would like dynamically create some controls - tablecells, textboxes, and dropdownlists inside an AJAX UpdatePanel.

How would I retrieve the values that user enters into these controls in my vb.net code behind?

Can you please provide vb.net sample code ??

Thank you for your help

http://forums.devx.com/showthread.php?t=16770

http://mail.123aspx.com/ArticleFrame.aspx?res=31558


here is a nice tutorial with example / code on how to create Dynamic controls and how to retrieve values from these dynamic controls.. [Page_Init() event is used here...]

SingingEels : Dynamically Created Controls in ASP.NET

hope it helps./.

2012年3月24日土曜日

Rich text editor in an update panel

I want to use a javascript editor like fckeditor in my webpage where the textarea is in an updatepanel.

But the textarea isn't is the welcome page, she apear when you click on a linkbutton.

How can i do for the editor to trigger when the textarea come or for the editor to load when i click the link.

Thanks in advance.I NEED YOU, HELP ME PLEASE

rjs Popcalendar in UpdatePanel

I've got a web page that allows users to enter X number of people for an application. I have an asp:Table contained in an UpdatePanel. The trigger for the UpdatePanel is a dropdown list that is used to select the number of people the user wishes to enter (1-14). On the initial page load only the 1st row in the asp:Table is visible and when the user selects how many people to enter I use an AJAX call to hide/show the appropriate asp:Table rows. Each row in the asp:Table contains a rjs:Popcalendar to select the date of birth. All the Popcalendar controls work fine if all the rows are set to Visible="true" on the initial page load. However, any row that has Visible="false" on the initial page load and is set to visible via the AJAX call gives the following error when the Popcalendar is clicked: Error: 'calResidentDOBX' is undefined

It appears that the page is only aware of the Popcalendar controls in the rows that are initially visible when the page loads. How can I make the page aware of the Popcalendar controls for the rows being set to Visible="true" in the AJAX call?

Thanks

Hi,

It's a javascript object undefined error,I think the simplest way to fix it is:

checking if there is a html control with it's ID set to "calResidentDOBX",

if there is no such control,the ASPX doesn't produce the right HTML,so check your logic in the behind-code.

if there is a such control,Try this:document.getElementById("calResidentDOBX")

debuging the javascript functions to see why the object is undefined.

Thanks


Hi,

I think the cause is:

When you set some controls's Visible="false" on the initial page load,ASPX doesn't generate HTML code for these controls. ASPX just generate HTML code for them when their Visible been set to "true" in Asynpostbacks.

But these controls cann't be accessed in javascript just use their IDs,you must use document.getElementById("ID") to access them.

Thanks


Download the new version from this urlhttp://es.geocities.com/ricaj0625

Use the libraryRJS.Web.WebControl.PopCalendar.Ajax.Net.dlland the javascripts in the directoryPopCalendar2005AjaxNet.

This version support ASP.NET AJAX from Microsoft

Saludos,

Ricaute


I'm not able to get the RJS popup calendar to work.

Not sure I know how to do the following steps properly:

Is it possible to break these steps down further? Thanks

5. Add RJS.Web.WebControl.PopCalendar.dll to the project Reference

6. Add RJS.Web.WebControl.PopCalendar.dll to the toolbar


Thanks. The popup calendar is working.

2012年3月21日水曜日

RoundedCornersExtender and DropDownList Causing Update Panel to Flash

I have run into a problem when I use the RoundedCornersExtender on an updatepanel. Everything functions as expected unless a DropDownList is contained on the container the RoundedCornersExtender is being applied to. If I place a DropDownList on the Div, on any partial post back, the entire page flashes. It still performs only a partial postback, but it appears that the entire page is being re-rendered. In this simple example it is only the update panel, but on my larger page (multiple divs, tables, etc) it seems all objects on the page flash.

Any help would be appreciated.

In Firefox, it seems to work fine, but I seem to be able to reproduce this problem with ease in Internet Explorer 6.

In my sample code, I have a button that does a simple postback and increments the count displayed in the label by 1.

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<cc1:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" Radius="6" Color="Blue" TargetControlID="MyContentDiv" />

<div id="MyContentDiv" runat="server" style="background-color: Red">

This is my content inside the div.

<asp:DropDownList ID="DropDownList1" runat="Server" />

</div>

<asp:Label ID="lblCounter" runat="Server">0</asp:Label>

<asp:Button ID="cmdCount" runat="server" OnClick="cmdCount_Click" Text="Count"></asp:Button>

</ContentTemplate>

</asp:UpdatePanel>

protected void cmdCount_Click(object sender, EventArgs e)
{
int tmpVal = 0;
int.TryParse(this.lblCounter.Text,out tmpVal);
tmpVal++;
this.lblCounter.Text = tmpVal.ToString();
}

Feel a little sheepish on this one. I incorrectly assumed that because it was so specific to having drop downs, something really screwy was going on. This was solved with the whole Setting Debug=False Solutions.

Cheers


Ok, now maybe I am going crazy. It seems to be happening again... Has anyone else been able to reproduce this problem?
I am having the same issue, roundedcornersextender or dropshadowextender with rounded corners are both causing the entire screen to flash when a dropdownlist or listbox are on the page. This must be a bug, I am using beta2, removing the rounded corners makes it go away
hey I am also getting same issue...any update on this?

Hi,

I am also having this problemCrying, hope someone from asp.net team or Microsoft ASP.NETAJAX team member will look into this problem seriously.

Kind Regards,

Dev


I'm just going to chime in for a October 2007 update that I am having this problem as well...

RoundedCornersExtender causes this same problem in my app... All that is in my UpdatePanel is a Gridview. Everything works as expected in Firefox 2.0.0.7 but I get the flash/reload with Internet Explorer 6.0.29. After this happens the Gridview is hidden from the screen. If I remove the RoundedCornersExtender, everything works fine.


By the looks of it, this seems to be a common issue. I'm using an updatepanel with the collapsiblepanel and it works great! Now, if I add any type of changing control such as a DropDownList or ListBox, the flashing beginsConfused. I came up with an alternative for the dropdownlist which was a navigational menu; bad idea! I click on the menu and all the other menus become frozen or won't refresh. So canned that idea. At this point I'm ready to trash the whole thing and start from scratch, let the whole thing flash! I hope this can be figured out.

JZee