Refresh Captcha Code with Updatepanel control in ASP>NET - 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";
}
}

Related

updatepanel refresh whole page in asp.net

I use updatepanel in my page like this.
but when I run my app when I click on button that's refresh all of my page.
I do'nt know what I can do to solve this error.
even I use treeview in other page that when I get this error the treeview icon dont show.
please help me.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updPanl" runat="server" RenderMode="Block" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
try this
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="updPanl" ChildrenAsTriggers="true" runat="server" RenderMode="Block" UpdateMode="Conditional" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
protected void Button1_Click(object sender, EventArgs e)
{
updPanl.Update();
}
after three days I can find this problem today so I answer this question maybe this help to otherone.
I use routin in my app so webresource and scriptresouce could not load in asp page
I use this code for do not route this resource
routeCollection.Add(new Route("{resource}.axd/{*pathInfo}", new StopRoutingHandler()));

update panel does not work

im trying to get the value of a dropdownlist and insert it into a label inside an update panel like the following:
<asp:UpdatePanel ID="udpTutorialDropDown" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="TutorialSeries" DataTextField="SeriesName" DataValueField="VideoSeriesNameID" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList><br />
<asp:SqlDataSource ID="TutorialSeries" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="ViewSeasonName" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:Label ID="lblEpisode" runat="server" Text="Label"></asp:Label><br />
<asp:TextBox ID="tbxURL" runat="server"></asp:TextBox><br />
<asp:TextBox ID="tbxDiscription" runat="server"></asp:TextBox><br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
and in code behind i have
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
lblEpisode.Text = DropDownList1.SelectedValue.ToString();
}
but i dont know why it doesnt update the label!! the text of the label remains the same!!! can someone spot the problem??
You have to put drop down list into existing Update panel as well...
Try to remove the trigger to get something like so
<br />
<asp:SqlDataSource ID="TutorialSeries" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="ViewSeasonName" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:UpdatePanel ID="udpTutorialDropDown" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="TutorialSeries" DataTextField="SeriesName" DataValueField="VideoSeriesNameID" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
<asp:Label ID="lblEpisode" runat="server" Text="Label"></asp:Label><br />
<asp:TextBox ID="tbxURL" runat="server"></asp:TextBox><br />
<asp:TextBox ID="tbxDiscription" runat="server"></asp:TextBox><br />
</ContentTemplate>
You need to call the Update() method of the update panel in your Event as shown below.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
lblEpisode.Text = DropDownList1.SelectedValue.ToString();
udpTutorialDropDown.Update();
}
All the best!
UPDATE
You must add AutoPostBack="true" property in the drop down list. And, ignore my previous instructions. I.e. calling the Update() method of the update panel. That's required only when you have UpdateMode="Conditional"
This should work :)

How can i work with the ASP.NET Update Panel?

in my asp.net application i have two dropdownlist,if i select the first one's one value means automatically want to change the values of dropdown two,but its not working.here is my asp code.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="State"></asp:Label>
<asp:DropDownList ID="ddlState" runat="server" Height="23px" Width="195px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem>--Select--</asp:ListItem>
<asp:ListItem>Kerela</asp:ListItem>
<asp:ListItem>Tamilnadu</asp:ListItem>
<asp:ListItem>Karnataka</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="District"></asp:Label>
<asp:DropDownList ID="ddlDistrict" runat="server" Height="23px" Width="189px" AutoPostBack="True">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
I copied your code as it is, and gave definition to selected index changed event as
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
ListItem li = new ListItem("text");
ddlDistrict.Items.Add(li);
}
and it worked beautifully. You might have some other issue. Can you copy your selected index changed event code?

Disable Postback for Linkbutton

Im using ASP.NET LinkButton.
I have a LinkButton which calls code behind from onclick:
on aspx:
<asp:LinkButton ID="LinkTest" runat="server" onclick="LinkTest_Click" OnClientClick="return false;" >LinkButton</asp:LinkButton>
on aspx.cs:
protected void LinkTest_Click(object sender, EventArgs e)
{
//code here
}
As you can see I have set OnClientClick="return false;" so that it wont do a postback.
The postback does not happens. But the code behind is not fired.
I want the code behind to fire and I want no postback when the linkbutton is clicked.
How can I do this?
Thanks.
Remove the OnclientClick attribute of the linkbutton. Try using an UpdatePanel like:
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LinkTest" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:label id="Label1" runat="server" Text="Initial Label" />
</ContentTemplate>
</asp:UpdatePanel>
Also, you will need to add a ScriptManager in your page.
Add the linkbutton inside updatepanel,
remove onclientclick attribute of the linkbutton:
Page:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblName" runat="server" Text="Old Value"></asp:Label>
<br />
<asp:LinkButton ID="lnkbtChange" runat="server" OnClick="lnkbtChange_Click">Change</asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
CodeBehind:
protected void lnkbtChange_Click(object sender, EventArgs e)
{
lblName.Text = "New value";
}

Not able to display label message on success/failure of AjaxFileUpload in ASP.NET

I want to upload a file using AjaxFileUpload control. This works fine.The problem is i am not able to display the success/failure message on Label of file uploaded.
.aspx code..
<form id="form1" runat="server">
<div>
<div></div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Label runat="server" ID="myThrobber" Style="display: none;"><img align="absmiddle" alt="" src="images/uploading.gif"/></asp:Label>
<asp:AjaxFileUpload ID="AjaxFileUpload1"
runat="server"
OnUploadComplete="AjaxFileUpload1_UploadComplete"
OnClientUploadError="uploadError"
OnClientUploadComplete="uploadComplete"
ThrobberID="myThrobber"
MaximumNumberOfFiles="1"
AllowedFileTypes=""
class="name_text1"
Width="200px" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:Button ID="BtnClose" runat="server" Text="Close"
onclick="BtnClose_Click" OnClientClick="Closepopup()"/>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<br />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
i want to display text on Label2 that file uploaded or not.
my .cs code:
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string message = "Storege Space is Exceeding its Limit";
Label2.Text = message;
}
How to display message on Label ? Any Suggesstion? Help appreciated
It might be problem due to update panel,
You have put the AjaxFileUpload inside the update panel,
so update panel controls not update all controls when ever your label fill with text in AjaxFileUpload1_UploadComplete event.
So please try after remove update panel or set the property UpdateMode="Conditional" of update panel.
Hope this will helpful to solve out your problem.
The latest version of the ajax file upload comes with an update progress.So if you use it, you don't have to put a label to display the failure/success text.
For more information and demo see this page : http://stephenwalther.com/archive/2012/05/01/ajax-control-toolkit-may-2012-release.aspx
function ReBindMaterialsGrid() {
if (rebindTimer == null) {
SetRebindTimeout();
} else {
clearTimeout(rebindTimer);
SetRebindTimeout();
}
}
function SetRebindTimeout() {
rebindTimer = setTimeout(
'var btn = document.getElementById("MainContent_AdminTabs_TabContainerMain_TabPanelMaterials_Materials_btnReBindGrid");' +
'btn.click();', 8888);
}
<asp:UpdatePanel ID="UpdatePanelUpload" runat="server">
<ContentTemplate>
<asp:Label runat="server" ID="lblThrobber" Style="display: none;">
<img src="../../Images/loading.gif" alt="Loading..." />
</asp:Label>
<asp:HiddenField ID="hdStitchAssetPathUpload" Value='<%# Eval("StitchAssetPath") %>'
runat="server" />
<asp:AjaxFileUpload ID="AjaxFileUploadPlank" ThrobberID="lblThrobber" runat="server"
OnUploadComplete="AjaxFileUploadPlank_UploadComplete" OnClientUploadComplete="ReBindMaterialsGrid" />
</ContentTemplate>
</asp:UpdatePanel>

Resources