I have GridView2 that populates from a query string. This is done by clicking a hyperlink in GridView1. It all works perfectly, but I want the window to be a specific size instead of in a new tab. How can I achieve this?
Here's my code in GridView1:
<asp:TemplateField HeaderText="DateHL">
<ItemTemplate>
<asp:HyperLink ID="hl1" runat="server" Target="_blank" NavigateUrl='<%# Eval("DateFormat", "~/DateProfile.aspx?sdate={0}") %>'><%# Eval("DateFormat")%></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Have you tried a call to window.open in the onclientclick event of the hyperlink instead of using navigateURL? You should probably try naming the window too.
window.open method quick reference
Use javascript:window.open() in NavigateUrl or event of
e.g:
NavigateUrl='<%# string.Format("javascript:window.open('~/DateProfile.aspx?sdate={0}', 'MsgWindow','width=200,height=100')", Eval("DateFormat")) %>'
OR
You can try the following to OnClick:
OnClick='<%# Eval("DateFormat", "javascript:window.open('~/DateProfile.aspx?sdate={0}', 'MsgWindow','width=200,height=100')") %>'
Related
In the ItemTemplate of TemplateField of the GridView itis posible to set value using functions from CodeBehind. In the example I call getImgUrl and getNavUrl to set Image and Navigate URLs. I would like to know the syntax required to call a JavaScript function instead of a code behind function. That is, the combination of brackets, percent signs, hashtags, etc.
<asp:HyperLink ID="hHoldEm" Target="_parent" runat="server" Font-Underline="false" ImageUrl='<%# getImgUrl(Eval("CER_ACTIVE"))%>' ToolTip="Hold/UnHold..." ImageWidth="20" NavigateUrl='<%# getNavUrl(Eval("CER_ACTIVE"), Eval("CER_NO"))%>'/>
You cannot call a function in code behind with a HyperLink by adding a OnClick event as you would a Button.
But you can call javascript function in an anchor like this
Click for JavaScript
So to do the same in the GridView you can do this
<asp:HyperLink ID="hHoldEm" runat="server" NavigateUrl='<%# "javascript:" + getNavUrl(Eval("CER_ACTIVE"), Eval("CER_NO")) %>' />
or
<asp:HyperLink ID="hHoldEm" runat="server" NavigateUrl='<%# "javascript:myFunction('" + Eval("CER_ACTIVE") + "', '" + Eval("CER_NO") + "')" %>' />
I have gridview in asp.net as:
<asp:TemplateField HeaderText="Shipment Received" ItemStyle-VerticalAlign="top" HeaderStyle-VerticalAlign="top">
<ItemTemplate>
<a href="#" id="aShipment" onclick="javascript:setIdRMA('<%# Eval("idRMA") %>','<%# Eval("idreturn")%>','<%# Eval("idorder")%>','<%# Eval("returnReason")%>','<%# Eval("returnFor")%>','<%# Eval("returnStatus")%>','<%# Eval("dateClosed")%>','<%# Eval("shipmentReceiveDate")%>','<%# Eval("resolution")%>','<%# Eval("sku") %>',lblShipmentReceived.ClientID);">
<asp:Label ID="lblShipmentReceived" runat="server" Text='<%# Bind("shipmentReceived")%>'></asp:Label>
</a>
</ItemTemplate>
</asp:TemplateField>
on click of anchor tag i am calling setIdRMA method of javascript
I want to send client id of label inside anchor tag to that function.
For that i written as shown in above:
lblShipmentReceived.ClientID
But this does not get passed.
Please help me.
Since you are using GridView you may not get ClientID directly, you can find label which is inside anchor tag by its relative referrance. First pass achor tag element by this keyword and access it in the function to find label.
onclick="setIdRMA(..,..,..,this);"
and in the function
function setIdRMA(..,..,..,obj)
{
var label = $(obj).find('span'); //asp.net label is rendered as span and there is only 1 label so you can use .find()
}
Use .children selector for this
And asp:Lable rendered as span on HTML page so you can find it by using span
<asp:TemplateField HeaderText="Shipment Received" ItemStyle-VerticalAlign="top" HeaderStyle-VerticalAlign="top">
<ItemTemplate>
<a href="#" id="aShipment" onclick="javascript:setIdRMA(this,'<%# Eval("idRMA") %>','<%# Eval("idreturn")%>','<%# Eval("idorder")%>','<%# Eval("returnReason")%>','<%# Eval("returnFor")%>','<%# Eval("returnStatus")%>','<%# Eval("dateClosed")%>','<%# Eval("shipmentReceiveDate")%>','<%# Eval("resolution")%>','<%# Eval("sku") %>',lblShipmentReceived.ClientID);">
<asp:Label ID="lblShipmentReceived" runat="server" Text='<%# Bind("shipmentReceived")%>'></asp:Label>
</a>
</ItemTemplate>
</asp:TemplateField>
Change your onclick function argument and add this as first argument in your JavaScript function and then change your javaScript function as below .
function setIdRMA(,,,){
alert($(this).children('span').attr('id'));
}
I've added a HyperLink control to a GridView within a TemplateField and I want it to redirect the user to a specific page, passing the ID from the selected row. The following works just fine:
<asp:HyperLink ID="hlViewBasketItem" runat="server" Text="Detail"
NavigateUrl='<%# Eval("BasketItemID", "/BasketItemDetail.aspx?popUp=true&id={0}") %>'>
</asp:HyperLink>
The ID evaluates correctly; for example: "/BasketItemDetail.aspx?popUp=true&id=52"
The problem I have is that I need to make a call to a Javascript function to control the display of my page (so that it appears within a popup). I've tried the following:
<asp:HyperLink ID="hlViewBasketItem" runat="server" Text="Detail"
NavigateUrl='<%# Eval("BasketItemID", "javascript:dnnModal.show('/BasketItemDetail.aspx?bid={0}&popUp=true',false,550,950,false)") %>'>
</asp:HyperLink>
...but I'm getting a "server tag is not well formed" error.
Is there a actually a way to do this?
This was the answer:
NavigateUrl=<%# "Javascript:dnnModal.show('BasketItemDetail.aspx?popUp=true&bid=" + DataBinder.Eval(Container.DataItem, "BasketItemID").ToString() + "')"%>
I can go to bed now :)
rather than using asp.net hyperlink add use html anchor tag and call java script function as follows:
//javascript function
<script>
function openPop(drp) {
window.open('/BasketItemDetail.aspx?bid='+drp+'&popUp=true', false, 550, 950, false);
}
</script>
// Anchor tag
Click Here
I have one GridView with Employee search results in it.
This GridView shows results of EmpNo, EmpName, Salary. For each EmpNo cell in the GridView, there is a link to ManageEmployee.aspx page.
Till here okay, no problem.
In ManageEmployee.aspx page there are two buttons 1.Update, 2.Cancel
When user clicks on Cancel button, the page should navigate to Employee results page.
Can anybody give suggestion how to do this?
Add in a HyperLink field in a TemplateField. If you pass the search term to the details page as ~/Details.aspx?query=John%20Smith this will make a URL that is ~/SearchResults.aspx?query=John%20Smith.
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# String.Format("~/SearchResults.aspx?query={0}", Request["query"]) %>'>Cancel</asp:HyperLink>)
</ItemTemplate>
</asp:TemplateField>
If you want JavaScript (be careful about postbacks)
<asp:TemplateField HeaderText="">
<ItemTemplate>
Cancel
</ItemTemplate>
</asp:TemplateField>
If you have troubles with postbacks you will probably need to add in a direct URL like the HyperLink version above, or simply a window.location=".." version instead of history.go().
if you are looking for navigation using ASP.Net you can use
Response.Redirect("Your URL")
Example on how to use it - MSDN
Use the onclick attribute:
onclick="javascript:window.location.href='/relative/path/to/employeeResults.aspx'"
I am unable to call a Javascript function on the OnLoad event of a asp:button
HTML
<asp:Button ID="btnFromCalOpen" runat="server" Text=" > " onLoad = "AllHide()" OnClientClick ="ShowCal()" />
Javascript
function AllHide() {
alert("Hello");
}
Please Help
You will need to use JavaScript to toggle styles like you are trying
<asp:Button ID="btnFromCalOpen" runat="server" Text="" OnClientClick ="ShowCal()" style="display:none;visiblity:hidden;" />
Original Comment You can't do onLoad with JavaScript for any button. What are you hoping to accomplish? We can help figure out that solution.
You can do it at the page level. The page has a javascript onload event.
You can't do that.
Here's why. The OnLoad event in ASP.NET for a control is fired while the server is building the page (on the web server), but before it sends it to the browser (running on the user's machine).
Code on the web server can't directly call code on the browser computer (which hasn't even got the page yet).
If you just want to hide the control, just do this in your markup:
<asp:Button ID="btnFromCalOpen" runat="server" Text=" > " visible="false" OnClientClick ="ShowCal()" />
Another approach (hidden control doesn't takes up space):
<asp:Button ID="btnFromCalOpen" runat="server" Text=" > " style="display:none;" OnClientClick ="ShowCal()" />
Another approach (hidden control takes up space)
<asp:Button ID="btnFromCalOpen" runat="server" Text=" > " style="visibility:hidden;" OnClientClick ="ShowCal()" />