how to bind function processing with updateprogress control in asp.net? - asp.net

On click on button function are not getting fired. Why this is happening.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="server"
AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<asp:Image ID="Image1" runat="server"
ImageUrl="~/images/ajax-progress.gif"
/>
<br />
Please Wait. This will take few minutes.
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnUpdate" runat="server"
Text="Update"
onclick="btnUpdate_Click"
Width="100px" />
</ContentTemplate>
</asp:UpdatePanel>
code behind :
protected void btnUpdate_Click(object sender, EventArgs e)
{
trunc();
ConsumerUpld(FileUpload1);
}
ConsumerUpld(fileupld) function updates table in database

Everything seam fine, so I tested your code by replacing it by a btnUpdate.Text = "updated";
protected void btnUpdate_Click(object sender, EventArgs e)
{
btnUpdate.Text = "updated";
//trunc();
//ConsumerUpld(FileUpload1);
}
Everything run smoothly, so your problems is within one of the 2 functions you call.
When an error occurs during an async postback, it show on the button of the browser page (the way it show depend of your browser). You should try to debug it with breakpoints or comment out the update panel to see what is happening.

Related

New Content in ASP.NET website without reloading the page

I am trying to build a site with a "Next" button to display next question on the same page without reloading the page or redirecting to another page but I can't figure out how!
You could use an UpdatePanel and a Scriptmanager.
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<asp:Label ID="Label1" runat="server" Text="Question 1"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
And in code behind just do what you always do
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Question 2";
}
You will find that the text of the label changes when the button is clicked without a page refresh.

Refresh Captcha Code with Updatepanel control in ASP>NET

I have a captcha code in my site.
sometimes needs to chenge that picture , but i dont want the whole page refreh.
i used updatepanel in this way :
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblmsg" runat="server" Font-Bold="True"
ForeColor="Red" Text=""></asp:Label>
<asp:TextBox ID="txtimgcode" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" ImageUrl="~/CImage.aspx" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Check" />
<asp:Button ID="Button3" runat="server" Text="refresh" OnClick="Button3_Click" />
</ContentTemplate>
</asp:UpdatePanel>
Here is Button3 code behind :
protected void Button3_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "~/CImage.aspx";
}
Button1 Works correctly But Button3 which should change the captcha picture doesn't work.
Am I missing something?
In addition if Iwant to use a refresh image instead of Button3,What controls should I use?
The image likely isn't updating during partial postback because the browser doesn't realize that the image content has changed since it been targeted to same page over and over. Adding querystring might help in this case one need to pass random id as querystring to the ImageUrl of the captcha.
protected void Button3_Click(object sender, EventArgs e)
{
Image1.ImageUrl = string.Format("~/CImage.aspx?img={0}", Guid.NewGuid());
}
There is nothing wrong with your code Kindly check if "~/CImage.aspx" is returning correct values or not. I have modified your code Kindly check:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Label ID="lblmsg" runat="server" Font-Bold="True"
ForeColor="Red" Text=""></asp:Label>
<asp:TextBox ID="txtimgcode" runat="server"></asp:TextBox>
<asp:Image Width="100" Height="100" ID="Image1" runat="server" ImageUrl="~/CImage.aspx" />
<asp:Button ID="Button1" runat="server" Text="Check" />
<asp:Button ID="Button3" OnClick="Button3_Click" runat="server" Text="refresh" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button3" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
protected void Button3_Click(object sender, EventArgs e)
{
if (Image1.ImageUrl == "Koala.jpg")
{
Image1.ImageUrl = "Close.png";
}
else
{
Image1.ImageUrl = "Koala.jpg";
}
}

button inside updatepanel cause entire page to refresh

I use two UpdatePanel tags, one has a Svg inside and I need to refresh its content when a button is clicked, and the button is inside another UpdatePanel. And I just realize my Page_Load function in codebehind gets executed everytime I click the button. I set the property UpdateMode="Conditional" already but not helping. Any idea why? Following is my code:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" id="GlobalUpdatePanel" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="ButtonPP" eventname="Click" />
</Triggers>
<ContentTemplate>
<svg width ="1024" height = "540"></svg>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="ControlUpdatePanel" runat="server" Visible="True" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button id ="ButtonPP" runat="server" Text="Run PP" OnClick="ButtonPP_Click" />
</ContentTemplate>
</asp:UpdatePanel>
Thanks in advance!
Since the Page_Load function in code behind gets executed everytime the button is clicked, I'd guess you need to add if (!IsPostBack) in there, something like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// code that's only executed at first load
}
}

Updating Label inside UpdatePanel

i have a label and button inside update panel, when i try to get the value from the label on the button click, i get the value from label, but when i try to set the value to the label, it does not happens, i checked for JavaScript error, but there wasn't any, does anyone have any guess what could be the reason. i am using dotnetnuke and here is my code
<asp:UpdatePanel ID="updSection6" runat="server"><ContentTemplate>
<asp:Label ID="lbl" runat="server" />
<asp:ImageButton ImageUrl="/images/edit.gif" ID="btnEditSectionStory6" runat="server" OnClick="Clicked" />
</ContentTemplate></asp:UpdatePanel>
and here's the code
protected void Clicked(object sender, EventArgs e)
{
lbl.Text="Welcome";
}
You need to add the following code
<Triggers>
<asp:PostBackTrigger ControlID="btnEditSectionStory6" />
</Triggers>
Just before your closing </asp:UpdatePanel>
So your code should look like:
<asp:UpdatePanel ID="updSection6" runat="server">
<ContentTemplate>
<asp:Label ID="lbl" runat="server" />
<asp:ImageButton ImageUrl="/images/edit.gif" ID="btnEditSectionStory6" runat="server" OnClick="Clicked" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnEditSectionStory6" />
</Triggers>
</asp:UpdatePanel>
ASP PostBackTrigger
Specifies a control and event that will cause a full page update (a
full page refresh). This tag can be used to force a full refresh when
a control would otherwise trigger partial rendering.
You can read more about UpdatePanel's and Triggers here.
C# (using the ImageClickEventArgs)
protected void Clicked(object sender, ImageClickEventArgs e)
{
lbl.Text = "Welcome";
}

__doPostBack not working for updatepanel on page where enableviewstate=false

I have an update panel on a page, and am using __doPostBack on a control inside the updatepanel called from javascript to do a postback and update the panel.
Everything works fine, until I set enableviewstate=false on the page.
The javascript still fires, but nothing happens on the server side.
well i don't understand but where lies your problem but this worked for me with a quick code
<div>
<asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true" EnablePartialRendering="true">
</asp:ScriptManager>
<div id="result">
<asp:UpdatePanel runat="server" EnableViewState="false" ID="udpnl" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button runat="server" ID="btn" Text="UnClicked" OnClick="btn_click" />
</ContentTemplate>
</asp:UpdatePanel>
<input type="button" value="DoPartialPost" onclick="__doPostBack('btn','')" />
</div>
The code behind
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_click(object sender,EventArgs e)
{
btn.Text = "Clicked";
udpnl.Update();
}

Resources