jelliaes
jelliaes

Reputation: 505

Is it possible to put a javascript in the PostBackUrl of the LinkButton

I want to know if its possible for a javascript to run in the linkbutton's postbackurl. Or is there any way to trigger a javascript in linkbutton.

<asp:LinkButton ID="LinkButton1" runat="server" CommandName="editlink" onclick="LinkButton1_Click" PostBackUrl="javascript:document.getElementById('sched').style.display = 'block';" >Edit</asp:LinkButton>

Upvotes: 0

Views: 1223

Answers (1)

luke2012
luke2012

Reputation: 1734

You can use OnClientClick. For example:

<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="MyFunction();" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>

It will fire before the OnClick event.

Your Javascript function:

<script type="text/javascript">         
  function MyFunction() {
   document.getElementById('sched').style.display = 'block';
  }
</script>

Add an UpdatePanel for an AsyncPostBack

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click" />
        </Triggers>
<ContentTemplate>
 <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="MyFunction();" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>
  <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
      <ProgressTemplate>
          <div id="sched">
            // Your code
          </div>
      </ProgressTemplate>
  </asp:UpdateProgress>      
</ContentTemplate>

Upvotes: 1

Related Questions