I have just started using .net and have a question about passing variables from one page to another.
I have found several tutorials on the subject but none that fit my issue. Here it is.
I have a page1.aspx that hashttp://www.domain.com/directory/index.aspx?tagID=name
In page2.aspx I have
<script runat="server">
Sub Page_load
Dim tagID As String = Request.QueryString("tagID")
End Sub
</script>
<body>
<form runat="server">
& tagID
</form>
</body>
And it is not working. Can someone let me know what I am doing wrong?
Thanks.
<SCRIPT runat="server"> Sub Page_load() If Not IsPostBack Then If Not Request.QueryString("tagID") Is Nothing Then Dim tagID As String = Request.QueryString("tagID") lbl.Text = Request.QueryString("tagID") End If End If End Sub</SCRIPT><FORM runat="server"> <body> asp:label id="lbl" runat="server"></asp:label> </body></FORM>Asp.Net is a whole different ballgame that Classic Asp, and would recommend you to pick up one of the many fine books on how to get started. My favourite suggestion is Asp.Net Unleahed, written by Stephen Walther (SAMS).
Inhttp://www.domain.com/directory/index.aspx?tagID=name,
shouldn't it be
http://www.domain.com/directory/page2.aspx?tagID=name
Just a note, if you are passing sensitive data make sure not to pass them by QueryStrings. You might check other solutions, safer to a certain extent.
Regards
hi
why dont you try theContext.Handlermethod for passing variables data into one form to another.
it is Pretty good & secure compare with other techniques(Qureystring)
through this you can create object of the one into another forms and access the variales.
i think it might be usefull for you
tegards
Rams123
When you make suggestions like this, you should also provide at least a link to examples on how to do it. Better yet, include some code to demonstrate. Otherwise we will have a lot of unnecessary postings back and forth. This is the poster's first, and he clearly states that he just started out with .Net. It's therefore more than doubtful that he has a clue what Context.Handler is about.
You should also all set your preferred programming language in your profiles to ensure that eventual code examples will hopefully be given in this language.
Thanks in advance.
I found this article helpful when I was learning this.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskpassingvaluesbetweenwebformspages.asp
Well its a very simple mistake. You declared tagID inside Page_Load event, so they scope of that varibale is only upto Page_Load which you cannot access outside that procedure. simply make it global and you can access.so your code shoulde b like this
<script runat="server">
Dim tagID As String
Sub Page_load
tagID = Request.QueryString("tagID")
End Sub
</script>
<body>
<form runat="server">
' Now here you can use tagID variable as it has page level scope now
</form>
</body>
Hope I am clear. ..
Worked perfectly! Thank you.
0 comments:
Post a Comment