mercredi 27 mars 2019

function to get image from database is not working

I'm new to Javascript. I want to add an icon to all my project's web pages. This icon changes accordingly to whoever logs in in my page. What i'm trying now is, in master page load (when i have all of its data in codebehind, including his chosen icon), i introduced a js function to change icon:

    (function icon(image) {
        var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
        link.type = 'image/x-icon';
        link.rel = 'shortcut icon';
        link.hre = image;
        document.getElementsByTagName('head')[0].appendChild(link);
    })();

(adapted from here: Changing website favicon dynamically)

im trying to call this function with Page.ClientScript.RegisterStartupScript() method:

  (protected void Page_Load(object sender, EventArgs e)
  {
  if (!Page.IsPostBack)
     {
        //...

        UserModel usuario = (UserModel)Session["usuario"];

        //...

        Page.ClientScript.RegisterStartupScript(this.GetType(), "icone", $"icone({(Bitmap)new ImageConverter().ConvertFrom(usuario.imagem)});", true);
     }
  }

The method is simply not executing(its not returning error either, it just "jump it"), and i sincerely have no idea why.

OOOOR, there may be a better way to do it, but i just cant figure it.

(I will later add validation for when user has no image in database. Assume for now it will never be null).




Aucun commentaire:

Enregistrer un commentaire