ASP Images Refreshing until first cycle - asp.net

I am working on an ASP project (fairly new to ASP) one weird thing I have noticed is that images appear to refresh until after the first circle of images, my page code is:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Image runat="server" ImageUrl="~/Images/1.png" ID="updateImage"></asp:Image>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="click" />
</Triggers>
</asp:UpdatePanel>
And the code behind is:
protected void Button1_Click(object sender, EventArgs e)
{
if (updateImage.ImageUrl != "~/Images/8.png")
{
//Get Image number
string image = updateImage.ImageUrl.ToString();
char[] file = image.ToCharArray();
int fileName = Convert.ToInt32(file[9].ToString());
fileName++;
updateImage.ImageUrl = "~/Images/" + fileName.ToString() + ".png";
}else
{
updateImage.ImageUrl = "~/Images/1.png";
}
}
When I click the button the first cycle of 8 images looks as though the page is reloading, but after that there is no reload on the page and the images just change smoothly, is this because ASP caches the images after the first cycle? Is there any way to stop it flickering on the first cycle?
Thanks.

Related

ProgressBar in UpdateProgress keeps expiring before the data is fetched

I have a GridView which shows some data and has a Button in the last column that combines the value of the 3 other columns.
I was able to refresh the GridView easily just by calling this Function GridData in the rowCommand.
protected void GridviewProcess_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "More")
{
objENT = new ENT();
int index = Convert.ToInt32(e.CommandArgument.ToString());
Label locCode = (Label)GridviewProcess.Rows[index].FindControl("lbl0");
Label SurveyNo = (Label)GridviewProcess.Rows[index].FindControl("lbl2");
Button Combine = (Button)GridviewProcess.Rows[index].FindControl("btnCombine");
Combine.Enabled = false;
objENT.LocationCode = locCode.Text;
objENT.SurveyNumber = SurveyNo.Text;
objENT.ProcType = "CREATECUSTOMER";
DataSet ds = new DataSet();
ds = BLL.CdCustomer(objENT);
}
}
catch (Exception ex)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Some Error occurred Please refresh the page')", true);
}
finally
{
Griddata();
}
private void Griddata()
{
objENT.ProcType = "PAGEGRIDDATA";
DataSet ds = BLL.ProcessGrid(objENT);
string check = ds.Tables[0].Rows[0]["TOTAL_CUSTOMER"].ToString();
GridviewProcess.DataSource = ds.Tables[0];
ViewState["Grid"] = ds.Tables[0];
GridviewProcess.DataBind();
}
After,I added this ProgressBar
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="UpdatePanel2">
<ProgressTemplate>
<img src="images/progress_bar.gif" style="max-width: 250px" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:GridView ID="GridviewProcess" AllowPaging="true" CssClass="GridHeader" PagerSettings-Mode="NextPreviousFirstLast" PagerSettings-PreviousPageText="<-Prev  " PagerSettings-Visible="true" PagerSettings-NextPageText="  Next->"
PagerSettings-FirstPageText="<=FirstPage  " PagerSettings-LastPageText="  LastPage=>" PagerStyle-Font-Bold="true"
OnPageIndexChanging="GridviewProcess_PageIndexChanging" PageSize="12" OnRowDataBound="GridviewProcess_RowDataBound" OnRowCommand="GridviewProcess_RowCommand" runat="server" Style="text-align: center" Width="99%"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Total Customers" HeaderStyle-BackColor="#99CCCC">
<ItemTemplate>
<asp:Label ID="lbl7" runat="server" Text='<%# Eval("TOTAL_CUSTOMER") %>'>
</asp:Label>
<asp:Button ID="btnCombine" CssClass="btn-primary btn" Text="Combine"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" CommandName="More"
Style="padding-top: 1%; padding-bottom: 1%; margin-top: 1px; margin-bottom: 1px" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAddi" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
The ProgressBar will show but after the function GridData(){} is called it wont refresh the GridView.
I can see the changes only after,I refresh the whole page.
I don't understand whats going wrong...
I don't have any JS or CSS used for this ProgressBar..(Is that the problem?)
Found the Solution to the Problem on SO questions
UpdateProgress Timed Out before data could be processed
Actual problem was :
I have a button on my ASP.NET page, which fetches some data from my database and displays it on a GridView.
This process takes a while, so I thought I'll add an updateprogress AJAX control. Now when I click the button, the UpdateProgress Image shows up and data is being fetched from my database successfully (I checked this from some logs that I have in my DB). But there are 2 issues:
The UpdateProgress image shows only for about 2 minutes. But my ButtonClick event takes about 5 minutes to complete. Basically the UpdateProgressstops showing up even before my task is complete, which defeats its purpose.
As I found this in one of the SO Answers
As per issue most likely it is ajax timing out. Default timeout is 90 seconds. To increase that use ScriptManager's AsyncPostBackTimeout property:
<asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="400">
</asp:ScriptManager>
If AJAX call is timing out, controls on the page might not work correctly so increasing timeout might solve problem (2) as well.

Image URL not changing in aspx page

I have got the following code snippet in my page
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="testButton" />
</Triggers>
<ContentTemplate>
<asp:Image ID="testImage" runat="server" ImageUrl="~/triangle.png" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button runat="server" ID="testButton" Text="Change Image" OnClick="testButton_Click" />
and have got the following in my code behind
protected void testButton_Click ( object sender , EventArgs e ) {
testImage.ImageUrl = "";
}
When I click on the button, the image is vanished since its URL has been set to empty string in code behind - I understand that. But when I view the page source, I see the original image URL as initialized in the asp page where I badly need URL to be set to empty string.
I have changed the ImageUrl value of your asp image in your markup as below:
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="testButton" />
</Triggers>
<ContentTemplate>
<asp:Image ID="testImage" runat="server" ImageUrl="<%#changeableImageUrl %>" />
</ContentTemplate>
Code Behind:
public string changeableImageUrl;
protected void Page_Load ( object sender , EventArgs e ) {
changeableImageUrl= "~/triangle.png"; // initial image URL
this.DataBind (); // since data have been bound in the page by data binding syntax
// <%#changeableImageUrl %>
}
protected void testButton_Click ( object sender , EventArgs e ) {
changeableImageUrl= ""; // to set html-rendered src attribute of img element to ""
this.DataBind(); //bind data to the page
}
changeableImageUrl must be declared public within the page. Now, you can change changeableImageUrl to change the image URL.
This is caused because the browser does not reload all source of page but if you change parameter in ScriptManager, In IDE, (not runtime). If you set to false EnablePartialRendering = false; this may solve your problem and always have new html code.

How can i refresh the UI using Component Art Callback in C# Asp.net

once the page is loaded if we need to add something on the UI then how we will do it by using callback without loading the whole page again.
You can use UpdatePanel to do this i.e. without refreshing your whole page it can change components of your page.
<asp:UpdatePanel ID="UpdatePanelMain" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="BtnClick" runat="server" OnClick="BtnClick_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BtnClick" EventName="Click" />
</Triggers>
Now you will get call in code behind whenever "BtnClick" button is clicked. There you can write your code.
protected void BtnClick_Click(object sender, EventArgs e)
{
// Your logic
}

can an Asp:Update Panel be Updated in a for loop, Simmilar To DoEvents() in windows forms

i have been trying to get an update panel to add controls to the screen as the code runs through a for look in the Back end C# code.
i have attempted this a lot of different ways, but no matter what i do i cant achieve this
is this possible to do using ASP.NET?
here is a simple example of what i mean.
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID='mng' runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UPPnl" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Add5" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:PlaceHolder ID="Place" runat="server"></asp:PlaceHolder>
<asp:Button ID="Add5" runat="server" Text="Add 5" OnClick="Add5_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
And the Code Behind
protected void Add5_Click(object sender, EventArgs e)
{
for (int i = 0; i < 5; i++)
{
Place.Controls.Add(new LiteralControl("Test" + i + "<br />"));
UPPnl.Update();
}
}
I was hoping i would get a new line of text every time i debug through the Update method. but this does not seem to want to work
Any Idea's?
Try adding this line in your Page_Load:
ScriptManager1.RegisterAsyncPostBackControl(Add5);

ASP Update Panel Stopped Working

Language: C#
Compiler: Visual Studio 2012
O/S: Windows 7 Home Premium
I have been using an UpdatePanel on my Content page for a while now, to update an Image based on text in a text box.
It all worked, up until now. Currently, the page does a full reload to display the image, instead of a partial post-back.
.aspx code
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Image ID="imgProfilePicture" runat="server" />
<br />
<asp:TextBox ID="txtImageLocation" runat="server" AutoPostBack="True" MaxLength="1000" CssClass="styleTextBoxCenter" Width="170px" OnTextChanged="txtImageLocation_TextChanged"></asp:TextBox><br />
<div style="padding-left: 4px;">
<asp:Label ID="lblImageUrl" runat="server" Text="Image URL" CssClass="styleLabelWatermark"></asp:Label>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtImageLocation" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
.cs code
protected void txtImageLocation_TextChanged(object sender, EventArgs e)
{
if(string.IsNullOrEmpty(txtImageLocation.Text))
{
imgProfilePicture.ImageUrl = RemoteReaderPlugin.Current.CreateSignedUrl("http://i.minus.com/iNQ7wK2opRJT1.gif",
new ResizeSettings(
"width=183&format=png"));
lblImageUrl.Text = "Image URL";
return;
}
if (!#txtImageLocation.Text.StartsWith("http://"))
{
#txtImageLocation.Text = "http://" + #txtImageLocation.Text;
}
WebRequest request = WebRequest.Create(#txtImageLocation.Text);
try
{
request.GetResponse();
imgProfilePicture.ImageUrl = RemoteReaderPlugin.Current.CreateSignedUrl(#txtImageLocation.Text,
new ResizeSettings(
"width=183&s.roundcorners=10"));
lblImageUrl.Text = "Image Verified";
lblImageUrl.ForeColor = System.Drawing.Color.Green;
}
catch (Exception)
{
imgProfilePicture.ImageUrl =
RemoteReaderPlugin.Current.CreateSignedUrl(
"http://i.minus.com/ibwhXZ9wLo1mOz.jpg",
new ResizeSettings("width=183&s.roundcorners=10"));
lblImageUrl.Text = "Invalid URL";
lblImageUrl.ForeColor = System.Drawing.Color.Red;
txtImageLocation.Focus();
}
}
I cant think of anything that I've changed, and the Master page still has a ScriptManager on.
Turns out, all functionality is lost on an UpdatePanel if you set a "Global" Routein your Global.asax.
The issue started when I added routes.MapPageRoute("", "{address}", "~/{address}.aspx");.
Upon removing, the ajax panels worked.

Resources