I am trying this function
of jquery
> $("[id*=btn_POPUP").click(function () { //this popup window
> var GV_VIEW = $(this).closest("tr")[0].rowIndex;
> window.open("Display.aspx?rowIndex=" + GV_VIEW, 'Popup',
> 'height=400,width=500,resizable=no,left=400,top=200,scrollbars=yes,menu=no');
> });
but this function not working properly any one give to me ideas please
> <Columns>
> <asp:TemplateField>
> <ItemTemplate>
> <asp:Button ID="btn_POPUP" runat="server" Text="POPUP" CssClass="btn btn-outline-primary" />
> </ItemTemplate>
> </asp:TemplateField>
> </Columns>
this the sample of button inside gridview
Display.aspx page examples
$(function () {
$(document).ready(function () {
new Clipboard(‘.copy-text’);
});
});
$(function () {$(document).ready(function () {
if (window.open != null)
{
var GV_details = window.location.href.split(“?”)[1].split(“=”)[1];var par = $(window.opener.document).contents();
var row = par.find(“[id*=GridView1]”).find(“tr”).eq(GV_details);
$(“#Category”).html(row.find(“td”).eq(1).html());
$(“#Final_Draft”).html(row.find(“td”).eq(2).html());}
});});
</head> <body> <form id="form1" runat="server"> <div> <center><h3><b>Category</b></h3> <span id="Category"></span> </center> <hr /> <b>DRAFT:</b><span id="Final_Draft"></span> <br /> <a class="copy-text" data-clipboard-target="#Final_Draft" href="#">copy Text</a> <hr /> </div> </form> </body> </html>
2
Answers
I can see some typos in your code. For example, at line 1 of your sample code,
> $("[id*=btn_POPUP").click(function ()
, you have not closed the square bracket. So, you could look by resolving them. Could you let me view your, server function too?Ok, lets break this problem down a bit.
First, I suggest you get/grab/adopt/use some kind of "dialog" utility. They work MUCH better then attempting to roll your own. And they tend to play nice with popup-blockers etc.
the next goal is to write as LITTLE client side code as possible. This not due to me not being all that fond of JavaScript, but the "more" with ease we can leverage server side code, then the less messy the solution becomes. And client side code is oh so nice to write anyway.
Now, there are 2 pop up (dialog) libraries I can suggest. The one from the ajaxtoolkit is very nice (since you don’t need to learn + know any JavaScript).
However, that is quite a "rather" large and complex library to adopt JUST for a simple dialog.
The other choice – one that I use with great success? I use the "dialog" from jQuery.UI.
Since you already have jQuery installed (don’t we all???), then adding jQuery.UI makes a whole lot of sense here.
So, then we have a gridview, and I suppose we drop into that GV a plane jane asp.net button.
That plaine jane (standard code behind) can then:
And the beauty of this approach is the "pop" dialog can have good old plain jane buttons. (such as a save, delete button). Do keep in mind that any post-back will collapse the dialog. However, in most cases, this is desirable, since when you say hit a save button, or delete button in that dialog, you want to run simple + easy button click code server side anyway. And that then solves tow issues.
We get to run nice server side code.
And since we doing a post-back, then the dialog box collapses without any extra code, which we also want to occur when done.
And while in a lot of cases, we want this dialog to center on the page, I OFTEN want the dialog to pop up beside, or even right below the button we just clicked. (this is also why I like/suggest using the jQuery.UI dialog. (it has VERY nice ability to position the pop dialog).
Also, nice for that jQuery.UI dialog is it can be "modal", and thus it will automatic gray out and disable the rest of the page for you. (again, more reasons why to use a existing dialog system – it has LOTS of features and abilities for you.
So, lets assume jQuery, and also then jQuery.UI is installed.
So, now whole business becomes rather easy.
We need 2 parts:
Our gridview.
A div (that is "hidden"), and that is the context of the pop dialog. That of course would be some plain jane asp.net controls to edit the data.
So, first up, our gv, nothing fancy:
note that I used a "button" as opposed to a asp.net button, but the code and event click works 100% the same (I only used the button since it supports the gylph-icons – no other reason).
So, first up our grid – and NOTE how it is a pure simple GV – no java script click events or anything.
And code to load above is this:
id Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
LoadData();
}
Ok, so now we see/have/get this:
So, now right below the gv, we add a div (it will be set to display none).
All that div does/have is the controls and content to edit a row. that div will then be a pop dialog with jQuery.UI.
So, this markup really does not matter much, it just plaine jane controls – all done by drag + drop from the tool box. A wee bit of styling.
but, for more of a complete example, I’ll post the markup (I could leave this out – just some more boring markup).
Note however, the style=display:none. So, while developing, I have display:normal, but when happy with the layout, then we hide it with display:none.
the markup in a "div".
Ok, so, now we need the jQuery.UI. that "little" bit of js code.
this is right below the above div.
That is ALL the js code we need.
Ok, so now the button click code.
That is this code:
or, if using VB, then this:
but, note how so far? Not very much code, and this is for both the code behind, and the client side js code.
So, we get the row. Pull the data, shove into the controls. (I have a floader routine – it just takes the row of data and automatic fills out the controls for me. I became VERY tired of writing that kind of code over and over – so that one routine can be used for ANY page. I map the controls by using a "made up" or "cooked up" attribute called "f". So, that how I define the database column. but, you can load up the controls ANY way you want.
Note the last line of that code, we THEN call the JavaScript pop dialog. And I pass it the control name (since I wanted the pop dialog to pop JUST right below the button clicked – a nice touch!!).
The end result now looks like this: