url redirection in ASP.NET [Resolved]

Posted by Anilbabu.M under ASP.NET on 8/3/2012 | Points: 10 | Views : 1927 | Status : [Member] | Replies : 25
I have one url like this http://www.example.com

I am passing one perameter like this "http://www.example.com/TagId=12345"

I want display URLName(Column Name) Value(EX:www.google.com) display That URL in my browser using ASP.NET

Plz help me

Actual URL is:http://www.example.com

I want RESULT:"http://www.example.com/TagId=12345\www.google.com"

Final result www.google.com,This value comming from DATABASE

zzcc


Responses

Posted by: Anilbabu.M on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down

Resolved
sorry,By mistake i am copying that Insert statement,
data in correctly their in database

zzcc

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

Posted by: Ranjeet_8 on: 8/9/2012 [Member] [MVP] Gold | Points: 50

Up
0
Down

Resolved
@Anilbabu.M
Mark As Answer, if this helps u.

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

Posted by: Gopesh9 on: 8/4/2012 [Member] Starter | Points: 25

Up
0
Down
You can use query strings to pass values from one page to another. It will also show that in the url.

G. S.
.Net Developer

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

Posted by: Anilbabu.M on: 8/7/2012 [Member] Starter | Points: 25

Up
0
Down
I am Trying But It Displying Only Column value,
But I want Open That value (EX:www.google.com) open Google website

zzcc

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

Posted by: Gopesh9 on: 8/7/2012 [Member] Starter | Points: 25

Up
0
Down
When you will get the value, then using Request.QueryStrings(""), get the url i.e. www.google.com and then redirect to that page using
Server.Transfer("www.google.com")

G. S.
.Net Developer

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

Posted by: Ranjeet_8 on: 8/7/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@Anilbabu.M
you want to redirect on another web site ??? ( url from database )

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

Posted by: Anilbabu.M on: 8/7/2012 [Member] Starter | Points: 25

Up
0
Down
yes ,
I want Load the page after,I am passing one Parameter TagId, basing on the TagId(column) display The corresponding Another column(EX:sitename) value(Ex:www.google.com) ,
For example I am passing TagId=1 That corresponding Sitename(column) value(ww.google.con) directly That website will open,
That my task

EX:
TagId sitename

1 www.google.com
2 www.gmail.com
3 www.asp.net

zzcc

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

Posted by: Anilbabu.M on: 8/7/2012 [Member] Starter | Points: 25

Up
0
Down
I am trying This example below Attaching Project using dept table basing on dept table deptno base displaydname as a web address
 Download source file

zzcc

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

Posted by: Ranjeet_8 on: 8/7/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this
 if (!IsPostBack)

{
if (Request.QueryString["TagId"] != null)
{
string PageName = "http://www.google.com"; // Value from Database based on Your Query String ID.
Response.Redirect(PageName);
}
}


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

Posted by: Gopesh9 on: 8/7/2012 [Member] Starter | Points: 25

Up
0
Down
Hey Anilbabu,

using Query Strings get the TagId = 1 value from the previous page, now by using this TagId = 1, get the url from the database.
Now when you will get the url just call Server.Transfer("Name of the url");

G. S.
.Net Developer

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

Posted by: Anilbabu.M on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down
Thank you for giving Answer my question,
its working normal redirecting ,

This value not coming from DB table,
once check my Attachment example sourcecode based on deptno column dname value(Www.google.com)will displa in Browser,

Send complete example sourcecode

Thank you,
anil

zzcc

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

Posted by: Anilbabu.M on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down
Give me the Complete source code

Thank you,
anil

zzcc

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

Posted by: Ranjeet_8 on: 8/8/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down

please find attached source code.

or Change ur GridView Design
 

<asp:GridView ID="GvEmp" runat="server"
EmptyDataText="There Are No Employees In Selected Department" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Redirect URL">
<ItemTemplate>
<a href='<%#"http://"+Eval("Dname") %>'><%#Eval("Dname") %></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

 Download source file

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

Posted by: Anilbabu.M on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down
Thank you so much,
I have a one more Question
I have select That particular Deptno immediately open that particular website in Dname column value, it is possible???

In my example is open Next page after selecting after it open ,



zzcc

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

Posted by: Ranjeet_8 on: 8/8/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,

string Dno = Request.QueryString["Dno"];
SqlConnection con = new SqlConnection(
@"Data Source=WIN-6B644RU4JEH\SQLEXPRESS;Initial Catalog=anil;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select Dname from DEPT where Deptno=" + Dno, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
string PageName = "http://" + dr[0].ToString();
con.Close();
Response.Redirect(PageName);


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

Posted by: Anilbabu.M on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down
Where to write that code
I am writting that code in second form but
Getting an error
error is:Invalid attempt to read when no data is present.

zzcc

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

Posted by: Ranjeet_8 on: 8/8/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
if u are getting error "Invalid attempt to read when no data is present."
it means your query will return Null value.

try this on second page load event.
       string Dno = Request.QueryString["Dno"];

SqlConnection con = new SqlConnection(
@"Data Source=WIN-6B644RU4JEH\SQLEXPRESS;Initial Catalog=anil;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("select Dname from DEPT where Deptno=" + Dno, con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
string PageName = "http://" + ds.Tables[0].Rows[0]["Dname"].ToString();
Response.Redirect(PageName);
}
else
{
// No Record found
}


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

Posted by: Anilbabu.M on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down
Getting an error
Error is:can't find the server at dname

zzcc

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

Posted by: Ranjeet_8 on: 8/8/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@ Anilbabu check ur database connectivity with sql or table data
Try this sample hard code on page load it will redirect u to www.google.com

  

DataTable dt = new DataTable();
dt.Columns.Add("Dname", typeof(string));
dt.Rows.Add("www.google.com");

if (dt.Rows.Count > 0)
{
string PageName = "http://" + dt.Rows[0]["Dname"].ToString();
Response.Redirect(PageName);
}
else
{
// No Record found
}


Note : Bind ur sql data with DataTable.

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

Posted by: Anilbabu.M on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down
there is no problem in database&connection,
Its working fine but i am select any one google ony will open,

What i am selecting that only will open corresponding dname value


zzcc

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

Posted by: Ranjeet_8 on: 8/8/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Please share ur Database Table structure with Data.

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

Posted by: Anilbabu.M on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down
USE [anil]
GO

/****** Object: Table [dbo].[DEPT] Script Date: 08/08/2012 16:38:02 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[DEPT](
[Deptno] [int] NOT NULL,
[Dname] [varchar](50) NULL,
[Loc] [varchar](50) NULL,
CONSTRAINT [PK_DEPT] PRIMARY KEY CLUSTERED
(
[Deptno] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF

*********
INSERT INTO [anil].[dbo].[DEPT]
([Deptno]
,[Dname]
,[Loc])
VALUES
(10,'www.google.com','vja')
GO
INSERT INTO [anil].[dbo].[DEPT]
([Deptno]
,[Dname]
,[Loc])
VALUES
(10,'www.asp.net','gun')
GO
INSERT INTO [anil].[dbo].[DEPT]
([Deptno]
,[Dname]
,[Loc])
VALUES
(10,'www.gmail.com','ong')
GO

zzcc

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

Posted by: Ranjeet_8 on: 8/8/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
check above in ur insert query, deptno are the same in all rows.
so insert Unique Deptno in all rows
For eg:

INSERT INTO [anil].[dbo].[DEPT]
([Deptno]
,[Dname]
,[Loc])
VALUES
(1 ,'www.google.com','vja')
GO
INSERT INTO [anil].[dbo].[DEPT]
([Deptno]
,[Dname]
,[Loc])
VALUES
(2 ,'www.asp.net','gun')
GO
INSERT INTO [anil].[dbo].[DEPT]
([Deptno]
,[Dname]
,[Loc])
VALUES
(3 ,'www.gmail.com','ong')
GO



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

Posted by: Anilbabu.M on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down
sorry,By mistake i am copying that Insert statement,
data in correctly their in database

zzcc

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

Posted by: Anilbabu.M on: 8/9/2012 [Member] Starter | Points: 25

Up
0
Down
Any idea solve my problem plz

zzcc

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

Login to post response