I have a LinkButton in a GridView I want it to run a function and in the same time shows a div by Id
<div id="viewEmployeeModal" class="modal fade" >
The View_user function is not to show the div it's a function that calls data from SQL Server.
I tried this inside a LinkButton and HyperLink both
<ItemTemplate>
<asp:HyperLink Id="View_btn" runat="server" Text="view"
href='<%# "javascript:void(0);" %>'Onclick="view_user" ></asp:HyperLink>
</ItemTemplate>
and this jQuery code:
$('#viewEmployeeModal').hide();
$("#View_btn").on('click', function () {
$('#viewEmployeeModal').show();
});
Any help? Thanks.
Well, first up, it's not clear why a link button is being used, say as opposed to a plain button, or that of even a image button.
However, it does not really matter which kind of button is to be used here, it just not all that clear why a link button is the choice here.
So, assuming we have a simple grid view, and say we drop in an asp.net button into that grid view.
Next up, since we wanting to call/use/have/enjoy some server side code, then I not at all clear why we need any client side JavaScript code to show/hide the div.
It is a simple matter to have the code behind to show/hide that div anyway.
So, say we have this simple grid view markup:
And code to load this gv:
And we now have this:
So, now let's drop a div right below the above gv markup.
This div (we assume) can be hidden on pageload.
And it just a bunch of simple labels and text boxes.
eg this:
So, it really don't matter what we have in the div area.
But note, we have a "id" and runat=server for the div. This allows the code behind to show/hide the grid.
So, our button click (the link button click) will load the div area with data from the "one row" we clicked on.
Hide the gv, and show the EditRecord div area.
So, the code behind looks like this for the link button click event
And say the "cancel" button in that div area, the code is this:
And now the result is this:
So, we can use the one button click event, code behind, and that code behind can both load some data, hide or show the div, and in this example, we hide the gridview, show the div.
And we don't have to use a link button, you can do 100% near same code, and use a plain asp.net button, or even say a image button.
And since we want to call some code behind say to get some data to fill out the div, that same code can also hide/show the div also.