views:

271

answers:

1

I have a link button with image and label inside it. After postback, the image and label is not visible.

< asp:LinkButton ID="AddNewRunLinkButton" runat="server" CssClass="Navigationlocalnav" OnClick="AddNewRunLinkButton_Click" >   < img id="Img1" src="../../Images/add_newIcon.gif" runat="server" alt="Add New Run" /> < asp:Label ID="addText" Text=" Add New Run" runat="server"> < /asp:LinkButton>

This link button is used to import/export data. I have added an attribute on click of this link button(AddNewRunLinkButton) to display a progress bar using javascript - SetInterval function. If I remove this attribute, the image and label is getting displayed, otherwise only link button is getting displayed.

AddNewRunLinkButton.attributes.add("onclick","javascript:DisplayProgress()");

function DisplayProgress() { timeid = setInterval("addBlock",100) }

function Addblock() { // Display a progress bar as follows - Increase the width of a div tag at this interval }

Any help?

A: 

Since your code examples doesn't give much to go on I'm posting something I think might be what you're trying to do.

Markup and Javascript:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>Untitled Page</title>
  <script language="javascript" type="text/javascript">
    var timeID = null;
    var width = 0;

    function DisplayProgress() {
      timeID = setInterval('AddBlock();', 100);
    }

    function AddBlock() {
      var p = document.getElementById("progressDiv");
      if (width < 1000) {
        width += 100;
        p.style.width = width + "px";
      }
      else
        timeID = clearInterval(timeID);
      }
  </script>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <asp:LinkButton runat="server" ID="lbAddNewRun" OnClick="lbAddNewRun_Click">
        <img src="--url to an image--" alt="Add New Run" />
        Add New Run
      </asp:LinkButton>
    </div>
    <div id="progressDiv" style="background-color: Green; width: 0px; height: 20px;"></div>
  </form>
</body>
</html>

Code-Behind:

protected void Page_Load(object sender, EventArgs e)
{
  lbAddNewRun.Attributes.Add("OnClick", "javascript:DisplayProgress();");
}

protected void lbAddNewRun_Click(object sender, EventArgs e)
{
  // Export/Import code.
}

This does not "hide" the image, for me atleast.

Remark:
Instead of adding the OnClick event in the code-behind you can add it directly in the markup since it is not dynamically created:

      <asp:LinkButton runat="server" ID="lbAddNewRun" OnClick="lbAddNewRun_Click" OnClientClick="DisplayProgress();">
        <img src="--url to an image--" alt="Add New Run" />
        Add New Run
      </asp:LinkButton>
Sani Huttunen
Hi Sani, The code is more or less similar...other than following differences... 1. I dont use clearInterval, as I want to start from 0, if width reaches 1000. 2. i have an asp:label control after image control ...which contain the text as -"Add New Run" When i looked into the view source...am able to see an anchor tag instead of link button...and nno image and label controls :(.The timer stops as the postback happens in my case...not using clearInterval..will tat be causing the issue ?
Anish Mohan
Could you post the AddBlock javascript function?
Sani Huttunen
function DisplayProgress(progressDiv) { var progressBar = document.getElementById("ProgressBar"); timerId = setInterval("addBlock('"+progressDiv+"')", 100); } function addBlock(progressDiv) { var progress = document.getElementById(progressDiv); progress.style.align = "left"; var width = parseInt(progress.style.width); if(width < 500) { progress.style.width=width+10+"px"; } else { progress.style.width="0px"; } progress.style.backgroundColor = 'blue'; progress.style.cssFloat = 'left'; progress.style.styleFloat = 'left'; }
Anish Mohan
I have two divs: ProgressBar which acts as a border for the inner div...Inner Div's width keep on increasing to reach 500px (which is total width of outerdiv - ProgressBar).
Anish Mohan
I cannot directly see any problems there that might cause the image to disappear. What are you doing in the AddNewRunLinkButton_Click event?
Sani Huttunen
I'm executing a serverside function and update a gridview using the result which i get from db side.
Anish Mohan
My image tag is having "runat" attribute...and urs is not having the same(is it a typo ?)
Anish Mohan
I've used your javascript functions and everything seems to work as intended. The image doesn't disappear. You're not "messing" anything with "img1" or "AddNewRunLinkButton" in AddNewRunLinkButton_Click?
Sani Huttunen
No...i'm not :(((((
Anish Mohan
I've tried both with and without the runat="server" attribute on the img tag and the image displays fine. You could try and remove it since it is not necessary to have it there if you're not doing anything with it in the code-behind.
Sani Huttunen