Reputation: 767
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.
Upvotes: 0
Views: 1093
Reputation: 123
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.
Upvotes: 1
Reputation: 365
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.
Upvotes: 1