troubleshooting Question

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

Avatar of awilderbeast
awilderbeastFlag for United Kingdom of Great Britain and Northern Ireland asked on
C#ASP.NET
9 Comments1 Solution317 ViewsLast Modified:
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

ASKER CERTIFIED SOLUTION
awilderbeast

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros