Add multiple parameters in URL asp.net - c#

I am currently trying to send 2 parameters through an URL in ASP.NET. I have been able to successfully send across 1 parameter. I am now wanting to learn how to send 2 across.
I am wanting to also send another ID as well that links to Favourite_ID similar to what is happening below with Recipe_ID
ASP.NET
<asp:HyperLink Runat ="server" NavigateUrl ='<%#"RecipePage?id=" + DataBinder.Eval(Container.DataItem, "Recipe_ID").ToString()%>' ID="Hyperlink1"><%#DataBinder.Eval(Container.DataItem, "Recipe_Name")%></asp:HyperLink></asp>

<asp:HyperLink Runat ="server" NavigateUrl ='<%#"RecipePage?id=" + DataBinder.Eval(Container.DataItem, "Recipe_ID").ToString()+"&YourId="+DataBinder.Eval(Container.DataItem, "YourId")%>' ID="Hyperlink1"><%#DataBinder.Eval(Container.DataItem, "Recipe_Name")%></asp:HyperLink></asp>
You can place you id name in place of YourId and can add multiple ids like above

<asp:hyperlink
runat="server"
id="hlReceipt"
navigateurl='<%# String.Format("RecipePage.aspx?id={0}&name={1}", Eval("Receipt_ID"), Eval("Receipt_Name")) %>'
text='<%# Eval("Receipt_title") %>'>
</asp:hyperlink>

Related

Pass parameter from Gridview column to Javascript

I need to pass an argument (which comes from my database) from a radgrid view column to my javascript (which opens a dialog box window). However, I can't put the "bind("Id")" as a parameter from where I call the javascript as href.
In simpler words, I am looking for a way to pass <% Bind("Id")%> to the javascript, OpenMyWindow, call instead of the hardcoded, 111, right now.
<telerik:GridTemplateColumn UniqueName="Meet" DataField="Subject" HeaderText="Meet">
<ItemTemplate>
<div style="text-align: center">
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Bind("Subject") %>' href="javascript: OpenMyWindow(111);" Width="30%">
</asp:LinkButton>
</div>
</ItemTemplate>
</telerik:GridTemplateColumn>
When I try "OnClick" instead of "href", my popup dialog box closes instantly and doesn't stay opened.
Try using "OnClientClick" and return false from your javascript method to prevent post back.
Alternatively. You could use a method passing in the DataIten. Then output an anchor tag created anyway you like:
<%# formatOpener(Container.DataItem) %>
With code behind of:
protected string formatOpener(object item)
{
ObjectType myObj = (ObjectType)item;
return String.Format("<a href=\"javascript:OpenMyWindow({0});\" width=\"30%\"/>{1}</a>", myObj.ID, myObj.subject);
}
I think you don't need a LinkButton, you could achieve it with an asp:HyperLink (which renders as a a tag):
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Subject") %>' NavigateUrl='<%# "javascript: OpenMyWindow(" + Eval("ID").ToString() + ");" %>'></asp:HyperLink>
Also, don't use Bind if you don't need it, for displaying purposes always use Eval.
User HyperLink control instead and try setting the NavigateUrl property of the HyperLink this way:
<asp:HyperLink ID="hlLink" runat="server" Text='<%# Bind("Subject") %>' NavigateUrl='<%#Eval("Id", "javascript: OpenMyWindow({0});")%>'>
hope it helps./.
I finally figured out and solved this issue. Actually, somebody told me on the other post that, CommandArgument is completely a server-side property and doesn't render any html attribute. So I can't change any button's attribute and fire click on it. I finally made "Id" come through the code behind and made it work.
aspx code
<telerik:GridButtonColumn UniqueName="Subject" DataTextField="Subject" HeaderText="Meeting">
<HeaderStyle Width="30%" />
<ItemStyle HorizontalAlign="Center" />
</telerik:GridButtonColumn>
Code Behind
var subjectLink = meetingRow["Subject"].Controls[0] as LinkButton;
subjectLink.Attributes.Add("onClick", "javascript: return OpenMyWindow('" + meetingId + "')");

Passing Values from asp.net to a c# method - Onclick

I need to send a value to Link_Click (which is a method) by clicking on this link :
<asp:HyperLink ID="TheLink" runat="server" Text='<%# Eval("ID") %>' onclick="Link_Click"></asp:HyperLink>
the Value is: Eval("name")
onclick is a client-side javascript event handler, so you can do it this way:
onclick="<%= "Link_Click(" + Eval("name") + ")" %>
Otherwise, HyperLink navigates to another page, and you need to add the NavigateUrl property to a value like:
NavigateUrl="Some.aspx?name=<%# Eval("name") %>"
if that will work, but I think you need to do it as:
NavigateUrl="<%= "Some.aspx?name=" + Eval("name").ToString() %>"

hyperlink template field onclick pass value to pageB to display its details

I am new to this:
In Visual Studio 2010, asp.net
Webpage A has a gridview with a column of hyperlink of companyid:
<asp:TemplateField HeaderText="Company" ItemStyle-Width="20%" >
<ItemTemplate>
<asp:HyperLink Text='<%# (Eval("Company"))%>' ID="HyperLink1"
Target="_blank" runat="server"
NavigateUrl= WHAT SHOULD I PUT HERE TO NAVIGATE TO PAGE B WHICH IS ALSO IN THE SOLUTION
</ItemTemplate>
</asp:TemplateField>
I want to navigate to another page that's also in the solution file, but I don't know what address to use as it's not some links that's hosted already like "google.ca"
For the new webpage, I don't want any buttons or like that, I just want a page to show the details of a company, using "select * from table where companyid= 'value_from_pageA_hyperlink'. How can I build the page so that it's url could be something like www.somepage/key=?" Or can I set up a global value so that I can pass the companyid in the hyperlink to the other page?
I have been crazed by those.
Use
<asp:HyperLink Text='<%# (Eval("Company"))%>' ID="HyperLink1" Target="_blank" runat="server"
NavigateUrl='~/PageB.aspx?companyId=<%# Eval("CompanyID")%>'/>
"~/" in an ASP.NET URL means that the address is relative to the current application.
You Can Send A Query String And Get it Through request.params
<asp:HyperLink Text='<%# (Eval("Company"))%>' ID="HyperLink1"
Target="_blank" runat="server"
NavigateUrl="page2.aspx?variablename=value"/>
and get it through
request.params["variablename"]
on another page
I think it Should work
http://msdn.microsoft.com/en-us/library/6c3yckfw(v=vs.100).aspx
<asp:TemplateField HeaderText="Company" ItemStyle-Width="20%" >
<ItemTemplate>
<asp:HyperLink Text='<%# (Eval("Company"))%>' ID="HyperLink1" Target="_blank" runat="server"
NavigateUrl='<%# GetCompanyUrl(Eval("Company"))%>'/>
</ItemTemplate>
</asp:TemplateField>
protected string GetCompanyUrl (object companyNum)
{
return "./NewPageName.aspx?companyId=" + companyNum.ToString();
}

hyperlink in gridview error

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=""
onclick="javascript:w= window.open(
<%# Eval("booking_id","hideFromStartborrow.aspx?booking_id={0}")%>,
'mywin','left=20,top=20,width=500,height=500,toolbar=0,resizable=0');">
new Window</asp:HyperLink>
I want to send it to another one, but it does not.And want to make the page smaller.
You can try this Hyperlink
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# String.Format("hideFromStartborrow.aspx?booking_id={0}", Eval("booking_id")) %>' onclick="javascript:w= window.open(this.href,'DownloadImage','left=20,top=20,width=500,height=500,toolbar=0,resizable=0');return false;">Open</asp:HyperLink>
OnClientClick will be executed in the client side and only if it returns true,it will be posted back to server..If its false then nothing will happen.. Inorder to deal directly with server side use onClick..Here you are using both javascript and server side code so i would recommend onclientclick..

Pass GridView id to javascript in asp.net

I am using the below code to handle the gridview dropdownlist on change event in clientside. In the mean time i want to pass the row id for my further process. But it's not working. But it's working while i call javascript without id.How can i pass the id to javascript.
<asp:TemplateField ItemStyle-Width="10px" HeaderText="Status">
<ItemTemplate>
<asp:DropDownList ID="ddl_status" runat="server" onchange='chng_status("<%#Bind("FLD_ID") %>")' >
<asp:ListItem></asp:ListItem>
<asp:ListItem>Realised</asp:ListItem>
<asp:ListItem>Non-Realised</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
function chng_status(value) {
alert('enter');
alert(value);
}
You can do that like this:
<asp:DropDownList ID="ddl_status" runat="server"
onchange='<%# Eval("FLD_ID","chng_status(\"{0}\");") %>' >
I am using string formatting to pass the value to a javascript function.
Note that i don't fully understand what you are trying to achieve

Categories