Showing posts with label url. Show all posts
Showing posts with label url. Show all posts

Thursday, March 29, 2012

Pass information through URL

Hi Guys,

I am trying to pass information through a URL. I have seen a VB example like

<a href="http://links.10026.com/?link=details.aspx?id={0}", Container.DataItem("EmployeeID"

Is the {0} supposed to be a placeholder or something?

Then in C#, i tried to just go something like

<a href='details.aspx?id=<%#DataBinder.Eval(Container.DataItem, "author_ID") %>'><%#DataBinder.Eval(Container.DataItem, "au_lname")%></a><br /
And it works like it should..

Does anyone have a reference of how to properly pass variables through a URL like this?
Or.. what is the proper name of this?

ThanksI am not sure exactly what you are looking for. This is the most basic way of passing variables to a web page. It is based on the GET method which appends the variable id and value to the URL string. There are a number of security issues with this method, as the variable values in plain text and viewable to the user and the amount of data that can be sent is restricted by the maximum allowed length of the URL string, usually 256 chars. However it's simplicity usually makes it useable in some situations.

The other method to pass variables to a web page is through the POST method. This is more secure and more information can be passed.
Hmm.. well thanks for the security warning but, still how would you do this? Security is not an issue at this point for this.

With C#, are you supposed to use a ?id={0} thing, or just skip the {0}, what is that even doing in VB.NET?

Thanks
Oh I see what you are asking now. Basically there is no correct way to build up the URL string, you can concatenate strings or even use a StringBuilder. As long as you build a URL string that is valid.

In the VB example the {0} is indeed a place holder that is replaced by the variable positioned after the ",". In your case the value of Container.DataItem("EmployeeID" ).

In C# I think you can use the {0} thing as well or you could use any of the other string concatenation symbols like the overloaded + operator.

A valid URL string is of the form:
[the URL] ie the webpage that you want to go to
? this indicates that GET variables are about to follow
name1 the name of the first variable
= equals
value1 the value of the first variable
& indicates the start of another variable
name2
=
value2

and so on.
Ah.. thanks

Is there some advantage in using the {0} over just leaving it out?

Monday, March 26, 2012

pass the web value from asp.net to asp by url

hi all,

i have two web files, one is *.aspx and the other is *.asp

i need pass textbox.text value from *.aspx to *.asp

so i can process the value(ex:string ) in *.asp

i pass the value like this

<a href="http://links.10026.com/?link=iflowall.asp?case_no=<%=(case.Text)%>&bank_no=<%=(bank_no.Text)%>">connect</a></p>

and receive from *.aspx like this

<td><%= Request.QueryString("case_no") %>於<%= Request.QueryString("bank_name") %></td>

in *.asp, it can't decode the string "bank_name" so the value is null why?

if the string is about number(ex:1234) it`s ok, but wrong when the string is chinses word(ex:中文)

Not a asp guru but you do not seem to have a query string parameter "bank_name" (only bank_no) when constructing the string in asp?
Yes you got the Query string wrong. As in your .aspx constructed url, the query string parameter is bank_no not bank_name

pass url parameter

Hi,

I want to pass a URL parameter from a hyperlinked column in my datagrid to a data list on another page.

How do I construct the select statement for the datalist page please?

Cheers,

JbDo you mean you want the hyperlink URL to be something like:

/SomeDir/SomePage.aspx?ID=TheValueFromSomeDataSourceField

If so, use a HyperLinkColumn. Set its DataNavigateUrlField to the
DataSource field from where you want the databound data to come from.
Then, set the DataNavigateUrlFormatString to:

"/SomeDir/SomePage.aspx?ID={0}"

Essentially, put {0} in the string wherever you want the actual
database value to appear.

(copy and paste from a scott mitchell usenet posting.. ;-).. )
henkm.

Thanks for the reply but i meant on the other page.

select * from tbltable where class_ID = ??

cheers,
JB
The post var can be retrieved with(c#):

So, you sql is going to be something like:

string sqlSelect = "select * from tbltable where class_ID = " + Request.QueryString["ID"];

is this wat you wanted to see, or do your mean the full page code to retrieve the data and show it?
Careful with that, it is wide open to Sql Injection attacks: what happens if I call youpageurl.aspx?ID=1;delete * from tbltable ?
Well, you lose all your data...
Please consider the use of the SqlParameter object to securely build your Sql queries.
bleroy,

Thanks for pointing this out.

Do you know of any good articles or examples of using the sql parameter object for this case?

Thanks all,
JB
Sure,http://samples.gotdotnet.com/quickstart/aspplus/doc/webdataaccess.aspx#param should be a good start.
What if you want to pass 2 parameter in the DataNavigateURLFormatString like:
/SomeDir/SomePage.aspx?id={0}&id2={1}

Where will you put the second field?

pass value to image control

This is my first time to use asp.net. I just want to get an image name passed from url (by using request.querystring), and then display this image, when user click the image, I also display the mouse coordinate. But I just can not get it to work, please help. Thanks. The following is my code:

<script runat="server">
Sub getCoordinates(sender As Object, e As ImageClickEventArgs)
mess.Text="Coordinates: " & e.x & ", " & e.y
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim imagename as String = Request.QueryString("name")
Dim imagePath as String =Server.MapPath("/keller/portrait/" & imagename)
End Sub
</script>
<html>
<body>
<form runat="server">
<p>Click on the image:</p>
<asp:Image
runat="server"
ImageUrl="<%=iamgePath%>"
OnClick="getCoordinates"/>
<p><asp:label id="mess" runat="server"/></p>
</form>
</body>
</html>
Welcome to the ASP.NET Forums, lily1.

The following update to your code will correctly show the image passed in with the QueryString.

<%@. page language="VB" debug="true" %>
<html>
<head>
<title>This is main Page</title>
<script runat="server"
Sub getCoordinates(sender As Object, e As ImageClickEventArgs)
mess.Text="Coordinates: " & e.x & ", " & e.y
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim imagename as String = Request.QueryString("name")
Dim imagePath As String = Server.MapPath("/keller/portrait/" & imagename & ".gif")
MyImage.ImageUrl = imagePath
End Sub

</script>
<html>
<body>
<form runat="server">
<p>Click on the image:</p>
<asp:Image runat="server"
id="MyImage"
OnClick="getCoordinates" />
<p><asp:label id="mess" runat="server" /></p>
</form>
</body>
</html>

The only difference is that I gave the asp:Image control an ID, and used this ID in your Page_Load code to set its ImageUrl property.

For details of how to get your imagemap working, see the following tutorial:
ImageMap.NET

I hope this helps.
Thanks for your help. I tried your script, The picture can be displayed correctly now, but when i click the picture, I got javascript error, it seems that function 'getCoordinates' does not execute at server instead it tries to run at client side. Here is url of the page:http://user1046822.wx15.registeredsite.com/keller/imagecrop_coodinates.aspx?name=test.jpg . Could you please tell me what is the problem? Thanks again.
> Could you please tell me what is the problem?

You've defined the problem yourself ... that getCoordinates tries to run at the client-side, not at the server.

Please go through the article I provided above. That will explain how to send click coordinates back to your server-side code.

Pass values from URL to other pages ?

i have a page A and Page B.
in Page A have 2 links to Page B. to display a set of date based on
condiction set in url.. like
in page A
link1 = pageB.aspx?id=1
link2 = pageB.aspx?id=2
so when page B opens it sould get the values from the url and run a queary..
like
SELECT * FROM TABEL WHERE KEY_ID= (value got some page A)
in page B i have a Dataview bind with 'SqlDataSource' i exactly dont know to
call the valus from URL...
your thoughs much appericated !Hi ,
You can get value from Url by using Request.Querystring["id"].
Thanks
Sharmila
You can use the QueryString property of the Request: Request.QueryString["id
"].
See
[url]http://authors.aspalliance.com/aspxtreme/sys/web/httprequestclassquerystring.aspx[
/url]
Hege Servold
hege.servold(AT)bekk.no
"velu" wrote:

> i have a page A and Page B.
> in Page A have 2 links to Page B. to display a set of date based on
> condiction set in url.. like
> in page A
> link1 = pageB.aspx?id=1
> link2 = pageB.aspx?id=2
> so when page B opens it sould get the values from the url and run a queary
.
> like
> SELECT * FROM TABEL WHERE KEY_ID= (value got some page A)
> in page B i have a Dataview bind with 'SqlDataSource' i exactly dont know
to
> call the valus from URL...
> your thoughs much appericated !

Pass values from URL to other pages ?

i have a page A and Page B.

in Page A have 2 links to Page B. to display a set of date based on
condiction set in url.. like

in page A

link1 = pageB.aspx?id=1
link2 = pageB.aspx?id=2

so when page B opens it sould get the values from the url and run a queary..

like

SELECT * FROM TABEL WHERE KEY_ID= (value got some page A)

in page B i have a Dataview bind with 'SqlDataSource' i exactly dont know to
call the valus from URL...

your thoughs much appericated !Hi ,

You can get value from Url by using Request.Querystring["id"].

Thanks
Sharmila
You can use the QueryString property of the Request: Request.QueryString["id"].
See
http://authors.aspalliance.com/aspx...uerystring.aspx

--
Hege Servold
hege.servold(AT)bekk.no

"velu" wrote:

> i have a page A and Page B.
> in Page A have 2 links to Page B. to display a set of date based on
> condiction set in url.. like
> in page A
> link1 = pageB.aspx?id=1
> link2 = pageB.aspx?id=2
> so when page B opens it sould get the values from the url and run a queary..
> like
> SELECT * FROM TABEL WHERE KEY_ID= (value got some page A)
> in page B i have a Dataview bind with 'SqlDataSource' i exactly dont know to
> call the valus from URL...
> your thoughs much appericated !

Saturday, March 24, 2012

Pass Variable through URL

Hi, I'm new to programming I want to know how to pass variable through URL
for example
http://localhost/index.html?username=check
then when the index page finish loading it can show up:
your name is checkWelcome to the ASP.NET forums, iwinmac.

Let me know whether you're learning C# or VB.NET, and I'll write an example in that language.

By the way, you wouldn't really want to put usernames into the URL like that. If you're planning to introduce a login system, you should look at theSecurity QuickStart tutorial.
I like to learn in VB.NET. I put username into the URL just for example. once I know how to get the variable from the URL I can put more stuff in to it.
use the following code in order to retreive the username into a string:

dim username as string = request.querystring("username")

If "http://localhost/index.html?username=check" was entered into a browser than the string would return "check"

As SomeNewKid2 said, The QuickStart Tutorials are always a great place for information.
Here is the code for your firstpage.aspx, where you ask the user for his or her username:

<%@. Page Language="vb" %>
<script runat="server"
Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)

' get the user's name from the textbox
Dim Username As String
Username = UsernameTextbox.Text

' we need to "encode" the username
' so that "Charlie Brown" becomes "Charlie+Brown"
Dim UsernameEncoded As String
UsernameEncoded = HttpUtility.UrlEncode( Username )

' now, we can move off to the next page
Response.Redirect( "secondpage.aspx?name=" & UsernameEncoded )

End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
Please enter your username:
<asp:Textbox id="UsernameTextbox" runat="server" />
<asp:Button id="SubmitButton" text="Submit" onclick="SubmitButton_Click" runat="server" />
</form>
</body>
</html>




Here is the code for secondpage.aspx, where you receive the username and display it:
<%@. Page Language="vb" %>
<script runat="server"
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

' get the user's name from the querystring
Dim UsernameEncoded As String
UsernameEncoded = Request.Params( "name" )

' we need to "decode" the username
' so that "Charlie+Brown" becomes "Charlie Brown"
Dim Username As String
Username = HttpUtility.UrlDecode( UsernameEncoded )

' now, we can display the username
WelcomeMessage.Text = "Welcome " & Username

End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:Label id="WelcomeMessage" runat="server" />
</form>
</body>
</html>




This is very simple. You would want to add a "RequiredFieldValidator" to ensure that the user actually enters a username.

However, I'll leave that as part of your learning.

I hope this gets you started. Any questions, please ask.

Pass variable through include url

Well,
I have made a template which shows the header.
Now in an empty page I include it on the top and this way it shows when I query the page also the header.
This works.
Now I want in the header there is a cell which is empty to show a message.
This message is dynamic, so it depends on what you give as message.
I could it make that when I query index.aspx?message=test that in my header(header.aspx) it shows the message test.
Now want to do it this way.
I query index.aspx
but in index.aspx I do an include this way:
<!--#include file="template/header.aspx"-->
that I make it this way:
<!--#include file="template/header.aspx?message:test"-->
this way I can show on my header a message in that empty cell without the user seeing it in the url.
Is this possible?

Eeek...
You're really going about this a hard way.
If you aren't using 2.0 (which I'm assuming you aren't) then I'd create the header as a UserControl.
Then just plop it on the page. You can easily create a Public Property on the header then, that is accessible from the page, that you can set the Text to...

Pass variable to URL string

In ASP.NET, the HTML code, I have the following lines to pass variable MyType to the URL parameter:
<P><a id="aHome" runat="Server" class="nav"href="Main.aspx?HeaderType=<%= headertype%>">Home</a></P>
In my Main.aspx page, when I query the string as:Request.QueryString("HeaderType"), it always return me "<%=headertype %>", but not the value of variable: headertype.
How can I pass a variable value to URL string parameter.
Thanks.

You can use :

Response.Redirect("newPage.aspx?value="+TextBox1.Text);

Let me know if you need this to work when the hyperlink is clicked.

Hope this helps !


Thanksfor your answer, it works,
If you can tell me how to pass it to URL string, it will be very helpfull. Hyperlilnk does not have click event.

Pass Variable to URL string

I pass the variable in URL string as following:
<P><a id="aSupport" runat="Server" class="nav"href="Support.aspx?HeaderType=<%= headertype%>">Support</a></P>
When I query the string in Support.aspx, it always give me "<%= headertype %>", but not the value of the variable.
How Can I pass the value of the variable to URL string parameter.
Thanks.

Why not use an asp:hyperlink.

Then you can use the code-behind pages to set the link, etc.

Inline code is generally not the best choice.

Wednesday, March 21, 2012

Passing a parameter through the URL

I have a site that lets user register then adds them to a db but they are not active.

Then an email is sent to the admin who then goes to an asp.net page and activates the user if he chooses to.

My question is how can I pass the UserID in that email link so that when the admin goes to the generic 'Activate User' page the info for the user at that UserID is brought up?

Basically I want to pass the UID in the email URL link and then grab it when that page is hit later.Registerthem.aspx?UID=blahblahbla

then on Registerthem.aspx:

string UserID=Request("UID");