How to open Particular url from database using Query string?

Posted by Mandlaa under ASP.NET on 11/5/2013 | Points: 10 | Views : 1261 | Status : [Member] | Replies : 5
How to open Particular url from database using Query string?
This is my table

ID URL


1 http://forums.asp.net/

2 http://www.google.co.in/

I can pass ID as a Query string parameter like this

<li><a href="http://Mysite.azurewebsites.net/?Client=<%=Session["ID"]%>" target="_blank">URLS</a></li>

Based on ID particular url will be open?




Responses

Posted by: Bandi on: 11/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
The following URLs will give you an idea..
http://stackoverflow.com/questions/19333875/sql-server-entry-using-url-querystring
http://www.codeproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString
http://www.codeproject.com/Tips/574956/How-to-get-URL-and-QueryString-value-in-an-ASP-NET
http://www.kamath.com/columns/squareone/so003_aspvalues.asp

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 11/5/2013 [Member] Starter | Points: 25

Up
0
Down
I can write this code in Page load

con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
da = new SqlDataAdapter("Select URL from Table1 where ID =" + Session["USERID"], con);
cb = new SqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "Table1");
string pageUrl = ds.Tables["Table1"].Rows[0]["URL"].ToString();

Response.Redirect(pageUrl);

This code working fine

I want to this code working on Hyperlink click

Like below

<li><a href="http://Mysite.azurewebsites.net/?ID=<%=Session["USERID"]%>" target="_blank">URLS</a></li>

How can i modify my code?

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 11/5/2013 [Member] Starter | Points: 25

Up
0
Down
I can write this code in Page load

con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
da = new SqlDataAdapter("Select URL from Table1 where ID =" + Session["USERID"], con);
cb = new SqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "Table1");
string pageUrl = ds.Tables["Table1"].Rows[0]["URL"].ToString();

Response.Redirect(pageUrl);

This code working fine

I want to this code working on Hyperlink click

Like below

<li><a href="http://Mysite.azurewebsites.net/?ID=<%=Session["USERID"]%>" target="_blank">URLS</a></li>

How can i modify my code?

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
May be try same code within LinkButton control

Support links for the usage of Link button Clicks
http://www.c-sharpcorner.com/forums/thread/219467/open-in-new-tab-on-linkbutton-click-in-child-page-in-asp.aspx
http://stackoverflow.com/questions/9599536/open-new-window-in-asplinkbutton-click-event
http://stackoverflow.com/questions/10537811/using-a-button-to-open-a-link-in-a-new-tab-window-in-asp-net

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 11/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Instead of taking Anchor Tag, take link button and write on link button OnCommand event like below :-
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
if(e.CommandName.ToUpper.Equals("VIEW_DETAILS".ToUpper()))
{
string id = e.CommandArgument.ToString();
//now pass this ID in your window.open method as parameter to open new window
The syntax of the window.open method is given below:
window.open (URL, windowName[, windowFeatures]);
For example:-
window.open("http://Mysite.azurewebsites.net/?Client='"& id &"'", "mywindow1", "status=1,width=350,height=150");
}
}



Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response