Change masterpage image src from page in update panel C?

Since the image is sitting outside of the UpdatePanel, sever side changes will not be executed on the image after a partial postback. Your only option is to inject JavaScript into the page and change the image URL Use the ScriptManager. RegisterStartupScript Method to inject JavaScript after the partial postback Something like the following will work for you: C protected void btnPostback_Click(object sender, EventArgs e) { imgCompanyLogo.

ImageUrl = ResolveUrl("~/images/CompanyLogo/Logo. Png"); ScriptManager. RegisterStartupScript(btnPostback,this.GetType(), "myScript", "ChangeImage('" + ImageUrl + "');",false); } JavaScript function ChangeImage(imgURL) { //make sure the ID of the image is set correctly document.

GetElementById('imgCompanyLogo'). Src = imgURL; }.

Since the image is sitting outside of the UpdatePanel, sever side changes will not be executed on the image after a partial postback. Your only option is to inject JavaScript into the page and change the image URL. Use the ScriptManager.

RegisterStartupScript Method to inject JavaScript after the partial postback. Something like the following will work for you: C# protected void btnPostback_Click(object sender, EventArgs e) { imgCompanyLogo. ImageUrl = ResolveUrl("~/images/CompanyLogo/Logo.

Png"); ScriptManager. RegisterStartupScript(btnPostback,this.GetType(), "myScript", "ChangeImage('" + ImageUrl + "');",false); } JavaScript function ChangeImage(imgURL) { //make sure the ID of the image is set correctly document. GetElementById('imgCompanyLogo').

Src = imgURL; }.

Upvote: but what I really do is that I have javascript end request handler and frome it a call javascript function on master page, because the image is runat server so you cant edit it from child page :) – yasat Jun 8 at 13:29 That will work also. As long as JavaScript is being executed in some fashion then you'll be able to change the image src. Is that what you've done so far?

Is it working for you? – Alison Jun 8 at 13:31 ya it works, but is there another way to do it? Thanks in advanced – yasat Jun 8 at 13:37 There are lots of ways to do it but this is one of the quickest and most direct method.

– Alison Jun 8 at 13:38 1 Executing JavaScript on the client is certainly going to be the fast way. Why do you want to do it another way? – Alison Jun 8 at 13:53.

Wrap image by UpdatePanel with UpdateMode="Always" Master Page: public void SetImageUrl(string url) { Image1. ImageUrl = url; } Child Page: protected void UpdateImage(object sender, EventArgs e) { ((Main)Master). SetImageUrl("~/Images/0306d95.

Jpg"); } The code above works well for me.

The image is sitting outside of the UpdatePanel. Changing the UpdateMode won't affect anything that isn't inside the UpdatePanel. – Alison Jun 8 at 12:59 I don't mean to change UpdateMode of the panel on the child page, bu instead add another panel onto the MasterPage and place image into it.

– Yuriy Rozhovetskiy Jun 8 at 13:16 it not working! – yasat Jun 8 at 13:23 and in my case I also have link style sheet I want to change, so it is not efficiency – .

Have a look at Sys.WebForms. PageRequestManager Class. Define handler in javascript and may change the image source.

1: if you provided an example. – AhmadTK Jun 8 at 12:35.

If your code is being run after an async postback (per your UpdatePanel) then changes to anything outside the UpdatePanel will not be rendered. Content in the master page would definitely seem to qualify. If this is what you're trying to do, this model won't really work.

You will need to use some client script to effect changes to already-rendered content when working with this model. An UpdatePanel is a construct to identify an area that's updated through ajax. The page is not actually reloaded.So an postback can never change content that's outside of the UpdatePanel (or control bound to that panel) that sourced it.

Here's a basic implementation (using jQuery). Add a hidden field to pass the new source to the client. This must be inside the UpdatePanel.

Change this value from the server when you want the image to update with new_image_src. Value=ResolveUrl(...); Give your image a static id too to make life easier: Add javascript to the page (should NOT be in the UpdatePanel): function updateImage() { var new_src=$('#new_image_src'); if (new_src) { $('#dynamic_image'). Attr('src',new_src); /// erase it - so it won't try to update on subsequent refreshes new_src.

Val(''); } } $(document). Ready(function() { /// adds an event handler after page is refreshed from asp.Net Sys.WebForms. PageRequestManager.getInstance().

Add_pageLoaded(updateImage); }); This wouldn't be difficult to do without jquery either but seems more common than not these days.

– yasat Jun 8 at 13:22 Updated with a way to do it – jamietre Jun 8 at 13:42 thanks, bit that was I did as @Alison almost recommend, but can you give me another way :) – .

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions