Tutorial :Create PopUp with that is passing parameters



Question:

This HyperLink syntax is not working to pass parameters to a small PopUp window:

<asp:HyperLink ID="HyperLink2" runat="server" Text="Manage Related Items"      NavigateUrl='<%# "editRelatedItems.aspx?" + "ProductSID=" + Eval("ProductSID") + "&CollectionTypeID=" + Eval("CollectionTypeID")+ "&ProductTypeID=" + Eval("ProductTypeID") %>'      onclick="window.open('editRelatedItems.aspx?','name','height=550, width=790,toolbar=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=no'); return false;)      target="_blank" />  

Looks like the <asp:HyperLink> tag does not take the "onclick". Any ideas on how to get a pop up to fire that can get these parameters? I'm using C#, so perhaps there is a way to build the NavigateURL string in the code behind?

Thanks for any insight you may have.


Solution:1

<asp:HyperLink        ID="HyperLink2"        runat="server"        Text="Manage Related Items"       NavigateUrl="#"       onClick='<%# "window.open('editRelatedItems.aspx" +                     "?ProductSID=" + Eval("ProductSID") +                     "&CollectionTypeID=" + Eval("CollectionTypeID")+                     "&ProductTypeID=" + Eval("ProductTypeID") +                     ",'name','height=550, width=790,toolbar=no,                    directories=no,status=no,                    menubar=no,scrollbars=yes,resizable=no');                     return false;%>'         Target="_blank" />  

That should work, but I would really create a javascript method to call which would open the window.

<script type="text/javascript">     function openRelatedItems(productSID, collectionTypeId, productTypeId) {            window.open('editRelatedItems.aspx" +                     "?ProductSID=" + productSID +                     "&CollectionTypeID=" + collectionTypeID +                     "&ProductTypeID=" + productTypeID +                     ",'name','height=550, width=790,toolbar=no,                    directories=no,status=no,                    menubar=no,scrollbars=yes,resizable=no');        }  </script>  


Solution:2

From the server side code you can do

HyperLink2.Attributes.Add("OnClick", "yourstuffhere");  

that will allow you to specify the OnClick items.

You could also set the NavigateUrl to be something like "javascript: window.open..." if you wanted, again, can be done from the code behind.

also

Given that a Hyperlink is just a standard run of the mill anchor tag, if you are doing all of this processing in the code behind, it might just be easier to build the whole link yourself to save some hassle.


Solution:3

Do you need the server-side Hyperlink control? If not, I would recommend just using a standard HTML anchor tag or if you need it to show dynamically, just to generate it in the back-end using a literal tag and write the markup to that(including the onclick). The question you need to ask yourself is "Do you feel lucky?" and "Do I need a server control?"

If not familar with it, research a bit about the ItemDataBound event.

Key code to place into your DataList's ItemDataBound event:

Dim lit as Literal = CType(e.Item.FindControl("Literal1"), Literal)    lit.Text = "<a onclick='YOURJAVASCRIPT' href='#'>YOUR TEXT</a>"  

This is by no means the entire code you should put in your event, like I said, research what the event can offer and go from there.


Solution:4

Your usage of onclick in your code is missing it's closing quote " and has an extra bracket ). That could be your problem.

onclick="window.open('editRelatedItems.aspx?','name','height=550, width=790,toolbar=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=no'); return false;"  

I've found that the javascript popups don't play nicely with ASP:HyperLink; Try to create the link via a normal anchor tag:

<a id="HyperLink2"        runat="server"        NavigateUrl='<%# "editRelatedItems.aspx?ProductSID=" + Eval("ProductSID") + "&CollectionTypeID=" + Eval("CollectionTypeID")+ "&ProductTypeID=" + Eval("ProductTypeID") %>'         onclick="window.open('editRelatedItems.aspx?','name','height=550, width=790,toolbar=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=no'); return false;"        Target="_blank">  Manage Related Items  </a>  


Solution:5

The NavigateUrl overrides the onclick event of an 'a' tag.

You want to set the target attribute and drop the onclick

http://www.w3schools.com/tags/tag_a.asp


Solution:6

Use OnClientClick instead of OnClick.


Solution:7

<asp:HyperLink        ID="HyperLink2"        runat="server"        Text="Manage Related Items"       NavigateUrl="#"       onClick='<%# "window.open('editRelatedItems.aspx" +                     "?ProductSID=" + Eval("ProductSID") +                     "&CollectionTypeID=" + Eval("CollectionTypeID")+                     "&ProductTypeID=" + Eval("ProductTypeID") +                     ",'name','height=550, width=790,toolbar=no,                    directories=no,status=no,                    menubar=no,scrollbars=yes,resizable=no');                     return false;%>'         Target="_blank" />  

where you closed " after starting url value. this code is showing error,the server tag is not welformed


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »