We help IT Professionals succeed at work.
Get Started

c# running a javascript and a codebehind function on same button?

awilderbeast
awilderbeast asked
on
314 Views
Last Modified: 2012-05-11
Hi all,
not sure if this is possible becuase a .net button on click has a value of javascript:dopostback_ etc


but basically, i want a code behind function to run then a javascript one i can make it do one or the other and at the moment the code is only doing the javascript one and ignoring the c# one

any ideas on how i can do this?
############################## aspx page
<script>
        $(document).ready(function () {
            $(".dialog-modal-history").dialog({
                height: 450,
                width: 700,
                autoOpen: false,
                modal: true,
                dialogClass: 'Dialog',
                title: 'Work History'
            });

            $('.butHistoryDialog').click(function () {
                $('.dialog-modal-history').dialog('open');
                // prevent the default action, e.g., following a link
                return false;
            });

            $('.dialogclose').click(function () {
                $('.dialog-modal-history').dialog('close');
                // prevent the default action, e.g., following a link
                return false;
            });
        });
        function HistoryClick() {
            dialog = document.getElementById("butHistoryDialog");
            dialog.click();
        }
    </script>
<asp:Repeater runat="server" ID="rptJobHistory" OnItemDataBound="rptJobHistory_OnItemDataBound">
                <ItemTemplate>
                    <tr class="<%# Container.ItemIndex % 2 == 0 ? "Odd" : "Even" %>">
                        <td>
                            <%# Eval("DateStart", "{0:MMM yyyy}")%>
                        </td>
                        <td>
                            <%# ifdatenotend(Eval("DateEnd", "{0:MMM yyyy}"))%>
                        </td>
                        <td>
                            <%# Eval("Title") %>
                        </td>
                        <td>
                            <%# Eval("Company") %>
                        </td>
                        <td>
                            
                            <asp:LinkButton ID="View" runat="server" CommandArgument=<%# Eval("ID") %>>Edit</asp:LinkButton>
                        </td>
                        <td>
                            <asp:LinkButton runat="server" OnClick="Delete" CommandArgument=<%# Eval("ID") %>>Delete</asp:LinkButton>
                        </td>

                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table></td>
                <td><asp:Button ID="butAddJobHistory" runat="server" Text="Add History" SkinID="MessageButton" CssClass="opener" />
                <input runat="server" ID="butHistoryDialog" type="button" class="butHistoryDialog" clientidmode="Static" /></td>
            </tr>
        </table>

####################### code behind

    protected void rptJobHistory_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    { 
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            LinkButton ViewHistory = e.Item.FindControl("View") as LinkButton;

            ViewHistory.Click += new EventHandler(History);
            smUpdate.RegisterAsyncPostBackControl(ViewHistory);
            ViewHistory.Attributes.Add("onclick", "javascript:HistoryClick();");
        }
    }

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE