I am using following code in gridview:
<asp:HyperLinkField runat="server" Text="Order" ItemStyle-Font-Underline="true" DataNavigateUrlFields="itemid" DataNavigateUrlFormatString="../Order.aspx?OID={0}" Target="_blank" />
A new popup window opens. But it remains open even if I close the main page(grid). How can I mask this popup ? I need to send ID of row clicked as querystring, hence using this code.
Can anyone help me with best way possible to achieve it and how to do that ? Masking or ModalDialog window or anything else ?
Thanks in Advance !
You can make a TemplateField and put a LinkButton in its ItemTemplate which will call the JS window.showModalDialog method.
<TemplateField>
<ItemTemplate>
<asp:LinkButton id="btn" runat="server" OnClientClick="window.showModalDialog ('http://blah.com/d.aspx?p1=' + '<%# Eval("someField") %>'" ... />
</ItemTemplate>
</TemplateField>
Related
I have one item template in grid view, which contains one link. I want while clicking that button it should open in a new tab like target= "_blank".
<asp:TemplateField HeaderText="Reportd Link" ItemStyle-HorizontalAlign="center" >
<ItemTemplate>
<button onclick="location.href='<%#Eval("ReportLinks")%>'" title='<%#Eval("ReportLinks")%>'> Link</button>
</ItemTemplate>
If you want to leave the button there you can change location.href = url call with window.open(url, '_blank'); call, that would open a link in a new tab.
this will work,
<input type="button" value="button name" onclick="window.open('http://www.website.com/page')" />
In gridview try this Code
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text="Enter Details" OnClientClick="OpenWindow('<%# Eval("id")%>',<%# Eval("start")) %>)" />
write a javascript methods
function OpenWindow(id,start)
{
window.open('Default.aspx','_blank');
window.location.assign(Default.aspx?goalText="+ id +"&ProductID="+ start)
}
<asp:GridView runat="server" ID="test">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="Aboutus.aspx">
<asp:ImageButton runat="server" ImageUrl="~/image/background-image-top_banner.jpg"
ID="img" /></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
When I click on the Image in the gridview, it is not going to Aboutsus page? WHy don't the anchor tag work here?
You might do something like this, to keep things simple
<img src='<%# Eval("ImageSource") %>' />
Or use src="your image location" , if that is static
Dont use image button this will behave as an asp.net button, therefore you have killed your link. Use asp:hyperlink instead
<asp:Hyperlink runat="server" Id="navAbtUs" NavigateUrl="AboutUs.aspx" ImageUrl="~/image/background-image-top_banner.jpg" ID="img" />
I'd also question why you are using a Gridview for this, you will have a column with repeated info.
Try like this chagne image button to simple asp image
<a href="Aboutus.aspx">
<asp:Image runat="server" ImageUrl="~/image/background-image-top_banner.jpg"
ID="img" /></a>
Imagebutton is always creating problem for me,
so i always use link button and giving image between it
like
<asp:linkbutton id="id1" runat="server" ><img src='<Eval("Imagepath" >' /> </asp:linkbutton>
I know this is not appropriate answer, but i have faced problems with image button inside gridview and saw some other guys also face, so i suggested, this is a good alternate of image button
by the way why it is needed to put image button inside linkbutton, you can simply keep asp image if not want to use html image
I am trying to execute some javascript on the click of a asp gridview's hyperlinkfield. The javascript executes fine but the page posts back so when the iframe flickers before showing (The javascript simply sets the iframe's source and then its display from none to block.). How can I go about disabling autopostback on this control since it does not have such an attribute?
<Columns>
<asp:hyperlinkfield Text="Update"
NavigateUrl="javascript:ShowForm('frmAddAudits.aspx');"
HeaderText="Update"
target="_blank"/>
<asp:hyperlinkfield Text="Add Findings"
NavigateUrl="javascript:ShowForm('frmAuditFindings.aspx');"
HeaderText="Add Findings"
target="_blank" />
</Columns>
CSS
.ShowMe{display:block;}
.HideMe{display:none;}
Javascript
function ShowForm(urlToGoTo){
document.getElementById('myiFrame').src = urlToGoTo;
document.getElementById('myiFrame').className = "ShowMe";
}
Try using the TemplateFiled and the anchor tag like this :
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="#" onclick="javascript:ShowForm('frmAddAudits.aspx');return false;">
</ItemTemplate>
</asp:TemplateField>
if you want you can set runat="server" and give it an ID
In your javascript event handler add return false so the browser does not continue the click action, in this case doing the postback.
Of course, ideally, you wouldn't be using <asp:HyperlinkField>. Have you considered using <a runat="server"> instead?
NavigateUrl="javascript:ShowForm('frmAddAudits.aspx');return false"
Try this NavigateUrl attribute in the markup
NavigateUrl="javascript:ShowForm('frmAddAudits.aspx');return false;"
And also you can try basic HTML anchor tag and javascript to open new window.
See if you are not doing anything on postback of these hyper links then what is the purpose to draw server side control.
These affects the performance while rendering on web page. So I would suggest you to use <a> insread of these hyperlinkfields
you can use instead :
<a href="#" onclick="javascript:ShowForm('frmAddAudits.aspx');return false;">
Postback will never occure in this case and reduce the rendering time and momory cost in comparative to byperlinkfield.
In my c# web app,
I'm trying to invoke an Ajax HoverMenuExtender from Javascript, rather than from hovering over an assigned control.
If I set the TargetControlID of the HoverMenuExtender to a control on my page and hover the mouse over it, the hover menu displays, however, I cannot get it to display by manually invoking it with javascript.
The Javascript I'm currently trying:
popup = $("body").find('HME1');
popup.show();
//popup._popupBehavior.show();
I've stepped through the code so I'm sure popup.show() is being called. But it seems like nothing happens. It seems like .Show isn't really what we want to do, but instead we need to "Invoke" the AjaxExtender somehow.
The HoverMenuExtender:
<cc1:HoverMenuExtender ID="HME1" runat="server" BehaviorID="HME1" TargetControlID="dummyLink" PopupPosition="Top" PopupControlID="PopupMenu"></cc1:HoverMenuExtender>
A dummy link i'm assigning the control ID to:
dummy
The panel i'm trying to display:
<asp:Panel CssClass="popupMenu" ID="PopupMenu"
runat="server">
<asp:LinkButton ID="article" runat="server"
CommandName="Edit" Text="Edit" />
<br />
<asp:LinkButton ID="LinkButton2" runat="server"
CommandName="Delete" Text="Delete" />
</asp:Panel>
Use the following code:
$find("BehaviourID")._popupBehavior.show();
Would appreciate if anyone could help me.
I have two columns in my gridview, 1st column is a templatefield for capturing rownumber of grid and 2nd column is a link button clicking on which i am opening a pop up window.
<Columns>
<asp:TemplateField HeaderText="RowNum" Visible="false">
<ItemTemplate>
<asp:Label ID="lblRowNum" runat="server" Text="<%#Container.
DataItemIndex + 1>"></asp:Label>
</ItemTemplate>
<asp:TemplateField HeaderText="FileName">
<ItemTemplate>
<asp:LinkButton ID="btn" runat="server" Text='<%#Eval("Empid")%>'
CommandName="Click" OnClientClick='<%# Eval("FileName", "window.open
(\"abc.aspx\",null,\"location=0,status=0,toolbar=0,
menubar=0,resizable=1\",\"true\");")%>'/>
</ItemTemplate>
</asp:TemplateField>
This works fine however i want to pass text of label(from first column) as querystring of popup window.
Could it be done in codebehind or within window.open of my javascript code which i am calling onclick event of link button.
Thanks in advance