Showing posts with label variable. Show all posts
Showing posts with label variable. Show all posts

Thursday, March 29, 2012

Pass one variable from one form to other

Hi,

I want to transfer the value of one variable ( basicaly text of a text filed) from one form to other form ...

i tried Server.Transfer("next_form.aspx") ..and then tried Request.Form("text_field") to retrieve it's content .. but doesnt work ...

i also tried Response.Redirect("next_form.aspx") ..and then tried Request.Form("text_field") to retrieve it's content .. but doesnt work ...

I think i am doing it wrong ... how can i do it .. anyone plz help :(

Thanks
imranIn your first form, put the following in your sub that gets called when you submit the form...

Response.Redirect("form2.aspx?myValue=" & myTextBox.Text)

Then in your second page...

Sub Page_Load()
TextBox2.Text = Request.QueryString("myValue")
End Sub
Hi,

When using Server.Transfer its preserveForm arguement to TRUE. This makes viewstate, event procedure available in destination form.

When using Response.Redirect, you can use querystring to pass information to the destination form like Response.Redirect("test.aspx?id=10");

HTH,
Shamir
Also see below article it could helps you

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconpassingservercontrolvaluesbetweenpages.asp

Pass parameters through a hyperlink?

Is it possible to pass parameters through a hyperlink?

For Instance -- HTTP://WWW.MYDOMAIN.COM/PAGE.ASPX?VARIABLE=ABCD

And then if I reference VARIABLE in code, it will be equal to ABCD? If this is not possible directly as I described above, how can it be possible, because I need to somehow pass variables/parameters through a hyperlink.

I know about Session("") already, and that can pass data between pages, I know, but I need to do it through a hyperlink somehow.

Thanks.Sure, you can access it via the QueryString property of the Request object:


string var = Request.QueryString["VARIABLE"];

The string var now has the value of "ABCD".
Thanks a million, works great! :)

Hello

I need to pass parameter through a hyperlink but I don't know how to do this.

I try this in HTML

NavigateUrl="javascript:popup('AddNewContact.aspx?text="+BrokerName+"&BrokerKey="+BrokerID+"',500,700)

It did work.

Can you help me?

THanks,


Guarumal,

What you are doing is different than the original post. His is a static URL and you are building a dynamic URL. This should be a new thread.

My first question is, are BrokerName and BrokerKey VB/C# variables or javascript variables? The most likely situation is that you are trying to build the NavigateURL property in the wrong place. If those are VB/C# variables you need to do this in the code behind page.

Pass Session Variable Value to Crystal Report?

I've got an aspx page that allows the user to select different options
whenever they want to run a report. On this page, I have added an
additional text box for the user to enter in comments about the report
they are running.

I would like to be able to have the comments that the user has entered
to appear on the report that is generated. I thought that I might be
able to pass this text to the report by using a session variable but I
have had no luck. It doesn't matter if I use a session variable to
accomplish this.

Can someone tell me how I can the user's comments from the web form
appear on the report?

Thanks!I figured out a way to accomplish this. I created a session variable
named UComments and stored the text that the user typed in it. On my
Crystal Report I created a blank formula field named UserComments I
next added the following code to my web form:

Dim oRpt As CrystalDecisions.CrystalReports.Engine.ReportDocum ent
= New CrystalDecisions.CrystalReports.Engine.ReportDocum ent()

'*** TELLING THE PROGRAM WHER THE REPORT IS LOCATED
'*** AND WHAT THE REPORT'S NAME IS. ***
oRpt.Load(Session("ReportLocation") & "Grant.rpt")

'*** CODE TO WRITE USER'S COMMENTS TO THE REPORT. ***
oRpt.DataDefinition.FormulaFields.Item("UserComments").Text = "'"
+ Trim(Session("UComments")) + "'"

CrystalReportViewer1.ReportSource = oRpt

crjunk@.earthlink.net (crjunk) wrote in message news:<e45e90aa.0308061021.788041e6@.posting.google.com>...
> I've got an aspx page that allows the user to select different options
> whenever they want to run a report. On this page, I have added an
> additional text box for the user to enter in comments about the report
> they are running.
> I would like to be able to have the comments that the user has entered
> to appear on the report that is generated. I thought that I might be
> able to pass this text to the report by using a session variable but I
> have had no luck. It doesn't matter if I use a session variable to
> accomplish this.
> Can someone tell me how I can the user's comments from the web form
> appear on the report?
> Thanks!

Pass Session Variable from 1.1 to 2.0

Hi, I need to pass a session variable from an ASP.NET v1.1 page to a
v2.0 page, but haven't been able to do it. The reason is because I
need to embed the 1.1 page in my intranet portal tool so I can ask it
the user id that is currently logged in (using Plumtree, .. I mean
BEA). The portal only supports v1.1. I want to pass that session
variable to multiple pages externally that are running v2.0. Is this
possible? Please help.Since session is application-specific, even if they were both ASP.NET 2.0 yo
u
still couldn't do it, since they are each running in a separate appDomain.
You would likely need to come up with some external state mechanism using
remoting to store the "session" with a unique key to both apps someplace
"outside" of each app (database, etc.).
Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"aperez" wrote:

> Hi, I need to pass a session variable from an ASP.NET v1.1 page to a
> v2.0 page, but haven't been able to do it. The reason is because I
> need to embed the 1.1 page in my intranet portal tool so I can ask it
> the user id that is currently logged in (using Plumtree, .. I mean
> BEA). The portal only supports v1.1. I want to pass that session
> variable to multiple pages externally that are running v2.0. Is this
> possible? Please help.
>

Pass Session Variable from 1.1 to 2.0

Hi, I need to pass a session variable from an ASP.NET v1.1 page to a
v2.0 page, but haven't been able to do it. The reason is because I
need to embed the 1.1 page in my intranet portal tool so I can ask it
the user id that is currently logged in (using Plumtree, .. I mean
BEA). The portal only supports v1.1. I want to pass that session
variable to multiple pages externally that are running v2.0. Is this
possible? Please help.Since session is application-specific, even if they were both ASP.NET 2.0 you
still couldn't do it, since they are each running in a separate appDomain.
You would likely need to come up with some external state mechanism using
remoting to store the "session" with a unique key to both apps someplace
"outside" of each app (database, etc.).
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"aperez" wrote:

Quote:

Originally Posted by

>
Hi, I need to pass a session variable from an ASP.NET v1.1 page to a
v2.0 page, but haven't been able to do it. The reason is because I
need to embed the 1.1 page in my intranet portal tool so I can ask it
the user id that is currently logged in (using Plumtree, .. I mean
BEA). The portal only supports v1.1. I want to pass that session
variable to multiple pages externally that are running v2.0. Is this
possible? Please help.
>
>

Monday, March 26, 2012

Pass UserID in hidden field

I am trying to pass the UserID from a session variable into a new record.
I have a hidden textbox with the userID session in it, but the UserID field is int,4
and the textbox only pases text (I think). So I get an input string error.
am I doing this right?
All help apreciated.
Thanks,
JBIf you've got in in session, you shouldn't need to pass it in from the hidden field.

Either way:

Convert.ToInt32(Session.Item("UserID"))

or

Convert.ToInt32(hiddedTextBox.Text)

Regards,

Xander
Thanks Xanderno,
I've been at this all afternoon with no luck.
I get "input string was not in a correct format"

The parameter code is

myCommand.Parameters.Add(New SqlParameter("@.MemberID", SqlDbType.Int, 4))
myCommand.Parameters("@.MemberID").Value = Convert.ToInt32(UserID)

and the hidden text box is

<asp:TextBox id="UserID" runat="server" text='<% session(UserID")%>' Visible="False"
The database types are correct - any ideas?

Much appreciated,
JB
That means (likely) that UserID is blank. Which, (Ah ha!) looking at your code, it would be.

First, he session variable needs to be written to the html in order to appear in textbox or hidden field.
You could do this with either the full Response.Write: Response.Write(Session.Item("UserID"))
Or with the shorthand equals sign: =Session.Item("UserID")

Beyond that, since you're using an ASP.Net TextBox, with the visibility property set to false,
even if the session variable *was* being response.written, it still wouldn't work, because that textbox wouldn't be sent to the browser!

So, let's try something like this instead:

<input id="UserID" type="hidden" value="<% =Session.Item("UserID") %>" /
And that should fix you up.

Xander
Thanks Xander,

I'm getting closer but it now passes a "0" to the DB
If I use 'input' with an id of UserName instead of a textbox then in code behind it does not get declared.
So I declare it by

Dim UserID as Int32

Does this mean I have already converted UserID and so do not have to use Convert.Toint32 (UserID.text)

but then in my parameters

myCommand.Parameters.Add(New SqlParameter("@.MemberID", SqlDbType.Int, 4))
myCommand.Parameters("@.MemberID").Value = UserID.what goes here? I only get a few choices and was hoping for 'value'

I'm sure this is wrong!
Thanks again.
JB
This is a totaly wrong assumption you make there..

Look at:

http://www.asp.net/Tutorials/quickstart.aspx

And find yourself a few samples to play with. It will help you to get the ideas one-by-one..

For the code above:


Dim UserID as Int32
//set the user id to 1
UserID = 1

myCommand.Parameters.Add(New SqlParameter("@.MemberID", SqlDbType.Int, 4))

//set my param to the value of the userid var.
myCommand.Parameters("@.MemberID").Value = UserID


Actually, you're pretty close already.

First off let's change the tag a bit.

<input name="UserID" type="hidden" value="<% =Session.Item("UserID") %>" /
Now, when you pull up the page, if you do a View | Source, you should see that tag on your page, with your UserID set as the value. If it doesn't have a value, then there is something wrong with your session variable that you need to hunt down.

Next, in you're code, you'll have this:

Dim UserID as Int32
'Now we have the variable, but we still have to assign it a value.

UserID = Convert.ToInt32(Request.Form("UserID"))
'Now that we have the UserID in the variable, pass it to the command object.

myCommand.Parameters.Add(New SqlParameter("@.MemberID", SqlDbType.Int, 4))
myCommand.Parameters("@.MemberID").Value = UserID
Thanks,

I have looked through all the quickstarts but canot find this.
All my other parameters pass properly except this one
The value must equal the hidden input session variable from the form but it just passes a "0"

Thanks for the help so far.
JB
Xanderno

That's fixed it!!

Thanks to you and the others for taking time to help me.
Cheers,
JB

Pass Value from HTML to Code Behind

Is it possible to pass a value coming from a javascript function in HTML to a

receiving variable in Code Behind?

My program passes a value to a function in HTML '**** This works fine ****'

'****** CODE BEHIND ******'

Private Sub MyDataGrid(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles MyDataGrid.ItemDataBound

Dim x As Integer

For x = 0 To 1

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

e.Item.Cells(x).Attributes.Add("onclick", "sample('" & e.Item.Cells(x).Text & "')")

End If
Next

End Sub

'MY PROBLEM IS IN HERE. I want to pass a variable back to the Code Behind

'******* HTML *******'

<script language="javascript"
function sample(j)

'PROCESS j AND PASS IT BACK TO A VARIABLE IN CODE BEHIND
{
</script
i tried to make a public variable in code behind but it wont get the value passed

i think it is because of ITEMDATABOUND.

PLEASE HELP ME . . . Please show me how to make this work. . .Not sure exactly what you are trying to do but one easy way to pass values to the server is using Hidden Fields, so the idea is before posting back to the server you set the value using classic javascript and then in the server you will be able to read it either using the Request.Form collection or if you add this as a runat=server control using the Control.Value property.
So in your .aspx page, add this:

<INPUT Type="Hidden" ID="Hidden1" Name="Hidden1"
and in your javascript sample function, you can manipulate this field throught the "document" object. And then in your codebehind, you can simply retrieve the value:

string theValue=Request.Form["Hidden1"];

pass value of a variable to user control

Hi,

Trying to pass a value to user control within a page.
1. Couldnt find a way to pass it from code behind file.
2. Trying to pass it from aspx page... using EditURL='<%
"mypage.aspx?myvar=" + myvalue %>' assigns value of EditURL=''
I have tried using a local variable... directly trying to read it off
Request object and even tried using session variable...

could be glad if someone could tell me how to get it right... thanks,

regards,

Hermit DaveYou need to use properties and pass them in the page load events for
example....

Doug Stevens, another MVP has this very useful example whih explains the
approach

http://www.dotnetjunkies.com/Articl...866F720AB013.dc
ik

--
Regards

John Timney (Microsoft ASP.NET MVP)
--------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
--------------

"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:uV5MEnQwDHA.556@.TK2MSFTNGP11.phx.gbl...
> Hi,
> Trying to pass a value to user control within a page.
> 1. Couldnt find a way to pass it from code behind file.
> 2. Trying to pass it from aspx page... using EditURL='<%
> "mypage.aspx?myvar=" + myvalue %>' assigns value of EditURL=''
> I have tried using a local variable... directly trying to read it off
> Request object and even tried using session variable...
> could be glad if someone could tell me how to get it right... thanks,
> regards,
> Hermit Dave
Hello John,

Thanks for the pointer. That article hopefully did show me what i wasnt
doing...
For same reason i did look around for the instance of user control in the
data member declaration earlier and couldnt find it...
Anyho... have to map the instance on aspx page to the code behind.. then i
should be able to populate the properties.. (ealier was passing hard coded
values from within aspx and that worked)
Thanks mate,

Regards,

Hermit Dave

"John Timney (Microsoft MVP)" <timneyj@.despammed.com> wrote in message
news:Od4uotQwDHA.3496@.TK2MSFTNGP11.phx.gbl...
> You need to use properties and pass them in the page load events for
> example....
> Doug Stevens, another MVP has this very useful example whih explains the
> approach
>
http://www.dotnetjunkies.com/Articl...866F720AB013.dc
> ik
>
> --
> Regards
> John Timney (Microsoft ASP.NET MVP)
> --------------
> <shameless_author_plug>
> Professional .NET for Java Developers with C#
> ISBN:1-861007-91-4
> Professional Windows Forms
> ISBN: 1861005547
> Professional JSP 2nd Edition
> ISBN: 1861004958
> Professional JSP
> ISBN: 1861003625
> Beginning JSP Web Development
> ISBN: 1861002092
> </shameless_author_plug>
> --------------
> "Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
> news:uV5MEnQwDHA.556@.TK2MSFTNGP11.phx.gbl...
> > Hi,
> > Trying to pass a value to user control within a page.
> > 1. Couldnt find a way to pass it from code behind file.
> > 2. Trying to pass it from aspx page... using EditURL='<%
> > "mypage.aspx?myvar=" + myvalue %>' assigns value of EditURL=''
> > I have tried using a local variable... directly trying to read it off
> > Request object and even tried using session variable...
> > could be glad if someone could tell me how to get it right... thanks,
> > regards,
> > Hermit Dave
"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:uV5MEnQwDHA.556@.TK2MSFTNGP11.phx.gbl...
> Hi,
> Trying to pass a value to user control within a page.
> 1. Couldnt find a way to pass it from code behind file.
> 2. Trying to pass it from aspx page... using EditURL='<%
> "mypage.aspx?myvar=" + myvalue %>' assigns value of EditURL=''
> I have tried using a local variable... directly trying to read it off
> Request object and even tried using session variable...
> could be glad if someone could tell me how to get it right... thanks,
> regards,
> Hermit Dave

I know you have already been pointed to the Properites as fits your
question.

Just as a side note though, you can also use a Cache object for passing
information to an from controls and web user controls. They are very handy.

--
Rocky Moore
www.HintsAndTips.com

Saturday, March 24, 2012

Pass variable between sub routines

For example, I have the following code:

<%@dotnet.itags.org. Page Language="VB" Debug="True" %>
<script language="vb" runat="server">
Dim var As String

Sub button1_click(sender As object, e As EventArgs)
var = "one"
Response.Write(var)
End Sub

Sub button2_click(sender As object, e As EventArgs)
Response.Write(var)
End Sub
</script>
<html>
<head>
<title>Untitled Document</title>
</head
<body>
<form runat="server">
<asp:Button ID="button1" OnClick="button1_click" Text="one" runat="server"></asp:Button>
<asp:Button ID="button2" OnClick="button2_click" Text="two" runat="server"></asp:Button>
</form>
</body>
</html
The problem is when I click button 2 it response.writes nothing. It should spit out "one". Is there anyway I can share variables between multiple subs?When you click button2, the page is reloaded and "var" is redecleared and the button1 value is gone. You may need use ViewState or Session State to keep the value when page reload or redirect to other page.

Pass variable between sub routines

Hi,

I'm trying to write some code that will create an order number by searching through an order_detail table for the highest numbered order number. Once found, I would like to pass this number to the FillOrder sub routine, which inserts it into the order_detail table. It looks like the findMax routine works, since the response.write statement a the end of it prints out the correct number. However, the response.write statements in the fillorder routine do not display, nor does the table get populated. I think the first problem is that I may not be passing the "highest" variable correctly.

I know the code is probably hack, but I would appreciate help/advice.

Thanks in advance.

Tom


Public Sub findMax()
Dim highest As Int32
Dim strMax As String
Const strMaxConn As String = "data source=ENVISAGENT1;initial catalog=tsproductsSQL3;integrated security=SSPI;persist security info=False;workstation id=ENVISAGENT1;packet size=4096"
Dim objMaxConn As New SqlConnection(strMaxConn)
Dim dsOrderHead As DataSet
Dim daOrderHead As SqlDataAdapter
dsOrderHead = New DataSet()

strMax = "SELECT MAX(order_num) as highest FROM order_header"
Dim CmdMax As New SqlCommand(strMax, objMaxConn)

If numOrders = 0 Then
highest = numOrders + 1
End If

If numOrders > 0 Then
objMaxConn.Open() 'open connection

'run SQL command
CmdMax.ExecuteNonQuery()

objMaxConn.Close() 'close connection
End If
Response.Write(highest)
FillOrder(highest)
End Sub

'populate order_detail table
Public Sub FillOrder(ByVal ordNum As Int32)
'findMax()

Const strFillOrdConn As String = "data source=ENVISAGENT1;initial catalog=tsproductsSQL3;integrated security=SSPI;persist security info=False;workstation id=ENVISAGENT1;packet size=4096"
Dim objFillOrdConn As New SqlConnection(strFillOrdConn)
Dim daFillOrd As SqlDataAdapter
Dim strFillOrdSQL As String

Dim detNum As Int32 = 0
Response.Write("DetailNum " & detNum)
Response.Write("PRoduct " & grdCart.Items(1).Cells(1).Text)

strFillOrdSQL = "INSERT order_num,detail_num,product_num,quantity,line_item_price INTO order_detail values (ordNum,detNum,pnum,quan,price)"

Dim CmdFillOrd As New SqlCommand(strFillOrdSQL, objFillOrdConn)

objFillOrdConn.Open()

' Iterate through all rows within shopping cart list
Dim i As Integer

For i = 0 To grdCart.Items.Count - 1
'for each item in cart,
'insert current order #, detail#,product, quantity & price
'into order_detail

detNum = detNum + 1

Dim pnum As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(1).Text)
Dim price As Decimal = Convert.ToDecimal(grdCart.Items(i).Cells(3).Text)
Dim quan As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(4).Text)

CmdFillOrd.ExecuteNonQuery()

Next

objFillOrdConn.Close()

Hi Tom,
There is no embeded variables in ADO.NET. You have to create command with parameters and use them. Alter your code this way (check types of parameters):

' ...
strFillOrdSQL = "INSERT order_num,detail_num,product_num,quantity,line_item_price INTO order_detail values (@.ordNum,@.detNum,@.pnum,@.quan,@.price)"

Dim CmdFillOrd As New SqlCommand(strFillOrdSQL, objFillOrdConn)
CmdFillOrd.Parameters.Add(New SqlParameter("@.ordNum", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.detNum", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.pnum", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.quan", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.price", SqlDbType.Decimal))

CmdFillOrd.Parameters[0].Value = ordNum
objFillOrdConn.Open()

' Iterate through all rows within shopping cart list
Dim i As Integer

For i = 0 To grdCart.Items.Count - 1
'for each item in cart,
'insert current order #, detail#,product, quantity & price
'into order_detail

detNum = detNum + 1
CmdFillOrd.Parameters[1].Value = detNum

Dim pnum As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(1).Text)
Dim price As Decimal = Convert.ToDecimal(grdCart.Items(i).Cells(3).Text)
Dim quan As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(4).Text)

CmdFillOrd.Parameters[2].Value = pnum
CmdFillOrd.Parameters[3].Value = quan
CmdFillOrd.Parameters[4].Value = price

CmdFillOrd.ExecuteNonQuery()
Next


Thank-you. I'll give it a try.
Ok I finally got around to trying the code - it looks like it may work, but again, nothing happens after the findMax sub routine listed above. It is as if it isn't even invoking. Also, I took the response.write("Highest = " & highest) statement out, and it still displays the text when the button is clicked. Why does this persist even though the statement is out? Does it also have something to do with the FillOrder sub routing apparantly doing nothing?

Thanks

Tom
There are only two possible explanations for persisting results of response.write:
1. Page is cached and not executed at all
2. You are running wrong version of page
How would I determine which one? I've tried deleting cache files to no avail.
Try to change something visual on page (add some text for example) and see if you receive changes when page is served.
I did all of that.

If you look at the connection strings in the code above, are they creating a cache that persists?

I created new pages and copied the code over to them. I changed the connection strings to "server=localhost;database=tsproductssql3;uid=sa;pwd=sa" and ran it. I got rid of the persistent response.write, and was able to display all of the others. However, I tried again, and got a database (primary key) violation which I have to sort out to see if the problems persist. I'll re-post then.

Thanks for your replies.

Tom
OK, cleared up the persist problem.

If you (or someone) could tell me if the original connection string (above) that I had would have created this cache & persist problem, that would be great. I'm still getting a lot of roadrash fumbling my way through my first ASP.NET project.

Thanks

Tom

Pass variable for use in Select Statement?

How do I pass a variable for use in my Select statement? My attempt below doesn't work.

Basically I want to pass the ID from the selected value of a dropdownlist for use as the variable to use in the select statement.

string passContractorID = Convert.ToString(ddl_JobTitles.SelectedValue);string query2 ="Select * FROM vw_bms_ActiveJobTitles WHERE contractorID = " + passContractorID +"";

SelectedValue is a string so you don't need to convert. You might need quotes around contractorID if that is a string.

string

query2 ="Select * FROM vw_bms_ActiveJobTitles WHERE contractorID ='" + DropDownList1.SelectedValue + "'";


pkellner thanks for your reply...

I was passing the inccorect ddl selected item and was the reason for the SQL error.

Is there a better way of writing the select statement above or a better practice perhaps?


Ok here is my current issue, I have a method that populates the databound with ana object datasource, the method for the select statement of the object datasource is in a seperate class, Data.cs .

How do I pass the selected value from a dropdownlist to this method?

Here is what I currently have...

 [DataObjectMethod(DataObjectMethodType.Select)]public static IEnumerable GetAllJobTitles() { DropDownList ddl_Contractors = (DropDownList)FormView_Descriptors.FindControl("ddl_Contractors");string sel ="Select * FROM vw_bms_JobTitles WHERE contractorID = " + ddl_Contractors.SelectedValue +""; SqlCommand cmd =new SqlCommand(sel,new SqlConnection(GetConnectionString())); cmd.Connection.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);return dr; }
Error is from this line..  DropDownList ddl_Contractors = (DropDownList)FormView_Descriptors.FindControl("ddl_Contractors");
ERROR: The name FormView_Descriptors does not exist in the current context.
The code works on the pag_load event in the code behind of the webform and I understand why it doesn't work, because you need to reference the page somehow but I don't know the code to do so?
 
 


if in VB and ID is alpha

try:

string query2 ="Select * FROM vw_bms_ActiveJobTitles WHERE contractorID = '" & passContractorID &"'";


if in VB and ID is alpha

try:

string query2 ="Select * FROM vw_bms_ActiveJobTitles WHERE contractorID = '" & passContractorID &"'";

Note: tick marks above (')" and "(')"


Jim,

In short you'll want to make a new method that excepts the contractorID parameter and secondly you'll need to "wire" that control into the select parameters of the objectdatasource that is bound to this method. This will effecively pass in the value of the dropdown as the parameter of the method call.

For example:

[DataObjectMethod(DataObjectMethodType.Select)]
public static IEnumerable GetAllJobTitles(int contractorID)
{
....
}

<asp:ObjectDataSourceID="ObjectDataSource2"runat="server"SelectMethod="GetAllJobTitles"TypeName="BLComponent"><SelectParameters><asp:ControlParameterControlID="ddl_Contractors"Name="contractorID"PropertyName="SelectedValue"Type="int"/></SelectParameters></asp:ObjectDataSource>
In addition I would highly suggest not "building" your SQL statements but instead using paramaterized queries. This is much safer and will prevent SQL injection attacks and also gets you out of the whole "quotes/double quotes/single quotes" issue.
For example:
[DataObjectMethod(DataObjectMethodType.Select)]
public static IEnumerable GetAllJobTitles(int contractorID)
{
string sel ="Select * FROM vw_bms_JobTitles WHERE contractorID = @.ContractorID"
SqlCommand cmd =new SqlCommand(sel,new SqlConnection(GetConnectionString()));
cmd.Paramaters.AddWithValue("@.ContractorID", contractorID) cmd.Connection.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
}
 Please note this is Pseudocode but pretty close. It may require some tweaking before you drop it into your code.
Hope this helps a bit. Let me know if I understood your problem correctly and if this answers your question.
Kind Regards,
Josh

I forgot to provide a link to some help found on the asp.net site related to this subject:

http://www.asp.net/learn/dataaccess/tutorial05cs.aspx?tabid=63

Also asp.net quickstarts have a nice little tutorial:

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/objectdatasource.aspx

Kind Regards,

Josh


Josh,

Thanks for your reply..

I did as you instructed, which makes sense.. but got this error.

Must declare the variable'@.contractorID'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the variable'@.contractorID'.

Source Error:


Line 41: SqlCommand cmd = new SqlCommand(sel, new SqlConnection(GetConnectionString()));
Line 42: cmd.Connection.Open();
Line 43: SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
Line 44: return dr;
Line 45: }

Source File: c:\Visual Studio 2005\Websites\BMS_2_0\App_Code\BMSData.cs Line: 43

Here is my modified code you sugessted modifying.

<asp:ObjectDataSource ID="ods_PayPlans" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetAllJobTitles" TypeName="BMSData"> <SelectParameters> <asp:ControlParameter ControlID="ddl_Contractors" Name="contractorID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource>

[DataObjectMethod(DataObjectMethodType.Select)]
public static IEnumerable GetAllJobTitles(int contractorID)
{
string sel ="Select * FROM vw_bms_ActiveJobTitles WHERE contractorID = @.contractorID";
SqlCommand cmd =new SqlCommand(sel,new SqlConnection(GetConnectionString()));
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
}


You forgot the add withparameter command mentioned above.


JimAmigo:

Here is my modified code you sugessted modifying.

<asp:ObjectDataSource ID="ods_PayPlans" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetAllJobTitles" TypeName="BMSData"> <SelectParameters> <asp:ControlParameter ControlID="ddl_Contractors" Name="contractorID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource>

[DataObjectMethod(DataObjectMethodType.Select)]
public static IEnumerable GetAllJobTitles(int contractorID)
{
string sel ="Select * FROM vw_bms_ActiveJobTitles WHERE contractorID = @.contractorID";
SqlCommand cmd =new SqlCommand(sel,new SqlConnection(GetConnectionString()));
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
}

Looks like you forgot to add the new parameter (@.contractorid) to the command objects parameter collection: cmd.Paramaters.AddWithValue("@.ContractorID", contractorID). Your procedure should like something like the following:

[DataObjectMethod(DataObjectMethodType.Select)]
public static IEnumerable GetAllJobTitles(int contractorID)
{
string sel ="Select * FROM vw_bms_ActiveJobTitles WHERE contractorID = @.contractorID";
SqlCommand cmd =new SqlCommand(sel,new SqlConnection(GetConnectionString()));
cmd.Parameters.AddWithValue(Paramaters.AddWithValue("@.ContractorID", contractorID);
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
}

Kind Regards,

Josh


Josh again thanks for the quick and great feedback.

It is working now.

But once I try to bind those two dropdownlists to display the data tables current selection.. I get this error..

ERROR: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.


Josh:

In case you haven't guessed, I'm trying to limit the selections of ddl_JobTitles based on the current contractorID selected in ddl_Contractors.

I would think this would be easier but I've have been beating my head against the wall for two days now.

Ideally, when the page first loads the selected values are selected based on the contractorID and jobtitleid already residing in the data table for a specific staff member.

If ddl_Contractors is selected, the page postsback and ddl_JobTitles only has items based on the contractorID that was selected from ddl_Contractors.

Of course I would want some type of error handling based on ddl_Contractors not having a corresponding contractorID in the ddl_JobTitles list but I must first crawl before I can walk.

I have found this example of how to perform this type of task...http://www.webswapp.com/CodeSamples/aspnet20/dependentlists/default.aspx

But for the life of me cannot understand the code because it is well above my current C# and asp.net knowledge at this point.


Any help on this isue would be greatly appreciated.

Jim,

Sorry for the delayed response, pre-christmas weekend craziness. We'll get this worked out for you. Couple quick questions before I start throwing up some sample code:

1) Are you in ASP.NET 1.X or 2.0?
2) Are these dropdowns being hosted inside of a control such as formview\detailview as the article link you provided does?

Generally speaking it sounds like what you're looking for is dependent dropdowns. If your using ASP.NET 2.0 and you are able to use a release candidate quality solution I would recommend using ASP.NET Ajax, Microsoft's AJAX toolkit currently in RC1. It has included with it a free toolkit of controls (called AJAXControlToolkit) that includes in a dependant dropdown control called CascadingDropdowns. It allows you to have as many dropdown controls chained together in a dependancy to load on demand. The nice aspect of this is it's all client side and no postbacks and IMO is very stable (Been using it in production since beta 2). Some examples and sample code can be found athttp://ajax.asp.net/ajaxtoolkit/CascadingDropDown/CascadingDropDown.aspx. All you need to do is download the ASP.NET Ajax libary and the toolkit (http://www.codeplex.com/Wiki/View.aspx?ProjectName=AtlasControlToolkit for the tookit andhttp://ajax.asp.net/ for the core library). Although this toolkit is RC1 I've found it to be very stable when it comes to CascadingDropDown functionality and as I mentioned I've been using in production since beta2 but as with all pre-release/beta products you do incure some risk.

If you happen to still be in the 1.1 world or beta/RC type soution is an option for you I'd be happy to provide you some sample code to get you going using normal dropdown binding and postback behaviors, if memory serves me right there can be a few gotcha's with it. Let me know.


Regards,

Josh

pass variable between webpage

I want to ask what is the best way to pass variable between asp.net we
pages, and user controls , any examples

-
dolla
----------------------
Posted via http://www.codecomments.co
----------------------Hi Dollar,

There are various ways in which ASP.NET helps you to pass information
from one page to another, it basically depends on your application.
In general, the applications use Session state to pass variables.

You can refer to the following link for complete details:

[State Management Recommendations]
http://msdn.microsoft.com/library/d...StateOption.asp

As for user controls, you can have public properties for the user control
which can be accessed by any page and also they will retain their values in
between
server round trips.

HTH

Mona[Grapecity]

"dollar" <dollar.1pp11p@.mail.codecomments.com> wrote in message
news:dollar.1pp11p@.mail.codecomments.com...
> I want to ask what is the best way to pass variable between asp.net web
> pages, and user controls , any examples?
>
> --
> dollar
> ----------------------
> Posted via http://www.codecomments.com
> ----------------------

pass variable between webpage

I want to ask what is the best way to pass variable between asp.net web page
s, and user controls , any examples?Hi Dollar,
There are various ways in which ASP.NET helps you to pass information
from one page to another, it basically depends on your application.
In general, the applications use Session state to pass variables.
You can refer to the following link for complete details:
[State Management Recommendations]
http://msdn.microsoft.com/library/d...StateOption.asp
As for user controls, you can have public properties for the user control
which can be accessed by any page and also they will retain their values in
between
server round trips.
HTH
Mona[Grapecity]
"dollar" <dollar.1pp11p@.mail.codecomments.com> wrote in message
news:dollar.1pp11p@.mail.codecomments.com...
> I want to ask what is the best way to pass variable between asp.net web
> pages, and user controls , any examples?
>
> --
> dollar
> ---
> Posted via http://www.codecomments.com
> ---
>

Pass variable to another page

I have a calendar form that sends the inputted date back to a text box .
Using the GET method, I would like to pass the date as a variable to another
asp page. How do I do this?
Thanks.Hi Marti,
Not sure if I understand your question. But in ASP.Net 2.0 you have to
ability to do cross-page positing. So you can just do a postback with
value of that textbox to your other page.
More info:
http://www.dotnetjohn.com/articles.aspx?articleid=176
http://msdn2.microsoft.com/en-us/library/ms178139.aspx
Ward Bekker
"Asp.Net Discussions for the Professional Developer"
http://www.dotnettaxi.com
"Free .Net 2.0 C# to/from VB.Net Code Converter"
http://www.dotnettaxi.com/Tools/Converter.aspx
Marti wrote:
> I have a calendar form that sends the inputted date back to a text box .
> Using the GET method, I would like to pass the date as a variable to anoth
er
> asp page. How do I do this?
> Thanks.
>
Ward,
Thanks - That's exactly what I was looking for. I was using a different
method to pass values. I have tried using the postback method but to no
avail. Below is the source page I am working with, can you tell me what I
should have on my target page?
Thanks.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Cross Page PostBack</title>
</head>
<body>
<form name="form1" id="form1" runat="server">
<h3>Cross Page PostBack</h3>
Enter Search Term:
<asp:TextBox ID="SearchTerm" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Search"
PostBackUrl="posttarget.aspx" />
<br />
</form>
</body>
</html>
"Ward Bekker" <ward@.NOequanimitySPAM.nl> wrote in message
news:4405fc87$0$2027$9a622dc7@.news.kpnplanet.nl...
Hi Marti,
Not sure if I understand your question. But in ASP.Net 2.0 you have to
ability to do cross-page positing. So you can just do a postback with
value of that textbox to your other page.
More info:
http://www.dotnetjohn.com/articles.aspx?articleid=176
http://msdn2.microsoft.com/en-us/library/ms178139.aspx
Ward Bekker
"Asp.Net Discussions for the Professional Developer"
http://www.dotnettaxi.com
"Free .Net 2.0 C# to/from VB.Net Code Converter"
http://www.dotnettaxi.com/Tools/Converter.aspx
Marti wrote:
> I have a calendar form that sends the inputted date back to a text box .
> Using the GET method, I would like to pass the date as a variable to
another
> asp page. How do I do this?
> Thanks.
>
Ok, I think I know out the code isn't working. Don't have 2.0 installed.
I'll install the 2.0 framework and give the crosspage post back a try..
"Martin" <bmquiroz@.email.com> wrote in message
news:%23ItZRAYPGHA.3460@.TK2MSFTNGP15.phx.gbl...
Ward,
Thanks - That's exactly what I was looking for. I was using a different
method to pass values. I have tried using the postback method but to no
avail. Below is the source page I am working with, can you tell me what I
should have on my target page?
Thanks.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Cross Page PostBack</title>
</head>
<body>
<form name="form1" id="form1" runat="server">
<h3>Cross Page PostBack</h3>
Enter Search Term:
<asp:TextBox ID="SearchTerm" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Search"
PostBackUrl="posttarget.aspx" />
<br />
</form>
</body>
</html>
"Ward Bekker" <ward@.NOequanimitySPAM.nl> wrote in message
news:4405fc87$0$2027$9a622dc7@.news.kpnplanet.nl...
Hi Marti,
Not sure if I understand your question. But in ASP.Net 2.0 you have to
ability to do cross-page positing. So you can just do a postback with
value of that textbox to your other page.
More info:
http://www.dotnetjohn.com/articles.aspx?articleid=176
http://msdn2.microsoft.com/en-us/library/ms178139.aspx
Ward Bekker
"Asp.Net Discussions for the Professional Developer"
http://www.dotnettaxi.com
"Free .Net 2.0 C# to/from VB.Net Code Converter"
http://www.dotnettaxi.com/Tools/Converter.aspx
Marti wrote:
> I have a calendar form that sends the inputted date back to a text box .
> Using the GET method, I would like to pass the date as a variable to
another
> asp page. How do I do this?
> Thanks.
>

Pass variable to another page

I have a calendar form that sends the inputted date back to a text box .
Using the GET method, I would like to pass the date as a variable to another
asp page. How do I do this?

Thanks.Hi Marti,

Not sure if I understand your question. But in ASP.Net 2.0 you have to
ability to do cross-page positing. So you can just do a postback with
value of that textbox to your other page.

More info:
http://www.dotnetjohn.com/articles.aspx?articleid=176
http://msdn2.microsoft.com/en-us/library/ms178139.aspx

--
Ward Bekker
"Asp.Net Discussions for the Professional Developer"
http://www.dotnettaxi.com

"Free .Net 2.0 C# to/from VB.Net Code Converter"
http://www.dotnettaxi.com/Tools/Converter.aspx

Marti wrote:
> I have a calendar form that sends the inputted date back to a text box .
> Using the GET method, I would like to pass the date as a variable to another
> asp page. How do I do this?
> Thanks.
Ward,

Thanks - That's exactly what I was looking for. I was using a different
method to pass values. I have tried using the postback method but to no
avail. Below is the source page I am working with, can you tell me what I
should have on my target page?

Thanks.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Cross Page PostBack</title>
</head
<body>
<form name="form1" id="form1" runat="server">
<h3>Cross Page PostBack</h3>
Enter Search Term:
<asp:TextBox ID="SearchTerm" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Search"
PostBackUrl="posttarget.aspx" />
<br />
</form>
</body>
</html
"Ward Bekker" <ward@.NOequanimitySPAM.nl> wrote in message
news:4405fc87$0$2027$9a622dc7@.news.kpnplanet.nl...
Hi Marti,

Not sure if I understand your question. But in ASP.Net 2.0 you have to
ability to do cross-page positing. So you can just do a postback with
value of that textbox to your other page.

More info:
http://www.dotnetjohn.com/articles.aspx?articleid=176
http://msdn2.microsoft.com/en-us/library/ms178139.aspx

--
Ward Bekker
"Asp.Net Discussions for the Professional Developer"
http://www.dotnettaxi.com

"Free .Net 2.0 C# to/from VB.Net Code Converter"
http://www.dotnettaxi.com/Tools/Converter.aspx

Marti wrote:
> I have a calendar form that sends the inputted date back to a text box .
> Using the GET method, I would like to pass the date as a variable to
another
> asp page. How do I do this?
> Thanks.
Ok, I think I know out the code isn't working. Don't have 2.0 installed.
I'll install the 2.0 framework and give the crosspage post back a try..

"Martin" <bmquiroz@.email.com> wrote in message
news:%23ItZRAYPGHA.3460@.TK2MSFTNGP15.phx.gbl...
Ward,

Thanks - That's exactly what I was looking for. I was using a different
method to pass values. I have tried using the postback method but to no
avail. Below is the source page I am working with, can you tell me what I
should have on my target page?

Thanks.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Cross Page PostBack</title>
</head
<body>
<form name="form1" id="form1" runat="server">
<h3>Cross Page PostBack</h3>
Enter Search Term:
<asp:TextBox ID="SearchTerm" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Search"
PostBackUrl="posttarget.aspx" />
<br />
</form>
</body>
</html
"Ward Bekker" <ward@.NOequanimitySPAM.nl> wrote in message
news:4405fc87$0$2027$9a622dc7@.news.kpnplanet.nl...
Hi Marti,

Not sure if I understand your question. But in ASP.Net 2.0 you have to
ability to do cross-page positing. So you can just do a postback with
value of that textbox to your other page.

More info:
http://www.dotnetjohn.com/articles.aspx?articleid=176
http://msdn2.microsoft.com/en-us/library/ms178139.aspx

--
Ward Bekker
"Asp.Net Discussions for the Professional Developer"
http://www.dotnettaxi.com

"Free .Net 2.0 C# to/from VB.Net Code Converter"
http://www.dotnettaxi.com/Tools/Converter.aspx

Marti wrote:
> I have a calendar form that sends the inputted date back to a text box .
> Using the GET method, I would like to pass the date as a variable to
another
> asp page. How do I do this?
> Thanks.

Pass Variable to another function

Hi,
I have a small question...Is there a way to do a postback to the same
page and pass a value to a function OnClick?

Example:

void GetCityName(string c)
{
string city = c;
}

Now I want to call this function by Doing a PostBack with a
asp:LinkButton.

So, here is the asp:LinkButton code.
<asp:LinkButton ID="mob" runat="server" Text="MOB"
OnClick="GetCityName('MOB')"></asp:LinkButton
Can this be done?

ThanksA Onclick serverside event must conform to the delegate signature of
the CommandEventHandler. You could store the value in a hidden html
input using javascript, then in your server event handler retrieve the
value by using Request.Form.GetValues.

Endo
Or store the value in a session variable.
i.e.
Session["city"] = city;

then have the event handler grab it
i.e.
city = (string)Session["city"];

<bcutting@.gmail.com> wrote in message
news:1129235285.953333.183460@.g44g2000cwa.googlegr oups.com...
> A Onclick serverside event must conform to the delegate signature of
> the CommandEventHandler. You could store the value in a hidden html
> input using javascript, then in your server event handler retrieve the
> value by using Request.Form.GetValues.
> Endo
I am total lost...
Does anyone have an example...

What I have is a map of Alabama. So now if I show Mobile, Montgomery on
the map...
and make each city as a LinkButton.

What I am doing is when the user clicks on (MOB) which is Mobile...I
have a query string that goes to a SQL Server and find data where the
city = 'mob'. I want to create a generic function that does this. So
everytime Ijust click a city all that I have to do is call the function
name and pass the city code.

Thanks

Pass Variable to another function

Hi,
I have a small question...Is there a way to do a postback to the same
page and pass a value to a function OnClick?
Example:
void GetCityName(string c)
{
string city = c;
}
Now I want to call this function by Doing a PostBack with a
asp:LinkButton.
So, here is the asp:LinkButton code.
<asp:LinkButton ID="mob" runat="server" Text="MOB"
OnClick="GetCityName('MOB')"></asp:LinkButton>
Can this be done?
ThanksA Onclick serverside event must conform to the delegate signature of
the CommandEventHandler. You could store the value in a hidden html
input using javascript, then in your server event handler retrieve the
value by using Request.Form.GetValues.
Endo
Or store the value in a session variable.
i.e.
Session["city"] = city;
then have the event handler grab it
i.e.
city = (string)Session["city"];
<bcutting@.gmail.com> wrote in message
news:1129235285.953333.183460@.g44g2000cwa.googlegroups.com...
> A Onclick serverside event must conform to the delegate signature of
> the CommandEventHandler. You could store the value in a hidden html
> input using javascript, then in your server event handler retrieve the
> value by using Request.Form.GetValues.
> Endo
>
I am total lost...
Does anyone have an example...
What I have is a map of Alabama. So now if I show Mobile, Montgomery on
the map...
and make each city as a LinkButton.
What I am doing is when the user clicks on (MOB) which is Mobile...I
have a query string that goes to a SQL Server and find data where the
city = 'mob'. I want to create a generic function that does this. So
everytime Ijust click a city all that I have to do is call the function
name and pass the city code.
Thanks

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 into a user control

Please help, I've been working on this for hours and can't seem to find an answer online.

I have a main page (index.aspx) that uses a usercontrol (DropDownSearch.ascx). Inside the usercontrol are 3 dropdownlists with a code behind file that fills them with data from a query. The query is based on a variable which is sent by the main (index.aspx) file. Inside the code behind for the main page (index.aspx) I try to send the variable over to the codebehind of the user control, but it keeps failing.

Here is the user control info in index.aspx:
<%@dotnet.itags.org.Register TagPrefix="MyControl" Tagname="DropDownSearch" src="http://pics.10026.com/?src=dropdownsearch.ascx"%>
<MyControl:DropDownSearch ID="SearchMenus" Runat="server"></MyControl:DropDownSearch
Here is the code for the index.aspx.cs:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MainPage
{
/// <summary>
/// Summary description for index.
/// </summary>
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.RadioButton Functional;
protected System.Web.UI.WebControls.RadioButton Pwb;
protected System.Web.UI.WebControls.RadioButton Decorative;
protected System.Web.UI.WebControls.RadioButton Microelectronics;
public string SqlCat1, SqlCat2;
protected SearchMenus DropDownSearch;

private void Page_Load(object sender, System.EventArgs e)
{

}

protected void CategorySelected(object sender, System.EventArgs e)
{

if (Functional.Checked)
{
SearchMenus.SqlCat1 = "1";
SearchMenus.SqlCat2 = "1";
}

if (Decorative.Checked)
{
SearchMenus.SqlCat1 = "2";
SearchMenus.SqlCat2 = "2";
}

if (Pwb.Checked)
{
SearchMenus.SqlCat1 = "3";
SearchMenus.SqlCat2 = "3";
}

if (Microelectronics.Checked)
{
SearchMenus.SqlCat1 = "4";
SearchMenus.SqlCat2 = "4";
}

}
}
}

Here is the user control code behind (dropdownsearch.ascx.cs):
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Enthone
{
/// <summary>
/// Summary description for tier.
/// </summary>
public class dropdownsearch : System.Web.UI.UserControl
{
SqlConnection SearchConnection;
protected DataSet MyDataSet = new DataSet();
public DropDownList TradeNames, Applications, Processes;
public string SqlCat1, SqlCat2;

private void Page_Load(object sender, System.EventArgs e)
{
SearchConnection = new SqlConnection("Server=localhost;uid=sa;password=;database=Enthone");
string MySqlStatement = "sp_DropDownsSql " +SqlCat1+", "+SqlCat2;
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySqlStatement, SearchConnection);
MyAdapter.Fill(MyDataSet);

TradeNames.DataSource = MyDataSet.Tables["Table"];
TradeNames.DataBind();

Applications.DataSource = MyDataSet.Tables["Table1"];
Applications.DataBind();

Processes.DataSource = MyDataSet.Tables["Table2"];
Processes.DataBind();

SearchConnection.Close();
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

}
}

ThanksHow is it failing? Do you get an exception? (If so, what is the complete exception text?) Incorrect results? What's going wrong?

Don
When I go to build it from vs.net I get this error in the index.aspx.cs file, "c:\inetpub\wwwroot\MyApp\index.aspx.cs(25): The type or namespace name 'SearchMenus' could not be found (are you missing a using directive or an assembly reference?)
"
Okay, that means that it can't find the SearchMenus namespace. Where is that located? In another project? Is it open in your VS.NET solution file? You'll need to add a reference to it in Solution Explorer, by right-clicking on References in the project with Index.aspx and adding a reference to the project or DLL.

There are lots of ways to configure these things in VS.NET though, so explain where SearchMenus is located and we should be able to figure out what's wrong.

Don
O.K. I got the whole thing working, but would definitly appreciatea look at my code to make sure I'm handling it the right way...

User Control Info on index.aspx:


<%@.Register TagPrefix="MyControl" Tagname="DropDownSearch" src="http://pics.10026.com/?src=dropdownsearch.ascx"%
<MyControl:DropDownSearch ID="SearchMenus" Runat="server"></MyControl:DropDownSearch>

Code Behind of index.aspx:


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MyNamespace
{
/// <summary>
/// Summary description for index.
/// </summary>
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.RadioButton Functional;
protected System.Web.UI.WebControls.RadioButton Pwb;
protected System.Web.UI.WebControls.RadioButton Decorative;
protected System.Web.UI.WebControls.RadioButton Microelectronics;
public string SqlCat1, SqlCat2;
protected MyNamespace.dropdownsearch SearchMenus;

private void InitializeComponent()
{

}

private void Page_Load(object sender, System.EventArgs e)
{
}

protected void CategorySelected(object sender, System.EventArgs e)
{

if (Functional.Checked)
{
SearchMenus.SqlCat1 = "1";
SearchMenus.SqlCat2 = "1";
SearchMenus.DbCall();
}

if (Decorative.Checked)
{
SearchMenus.SqlCat1 = "2";
SearchMenus.SqlCat2 = "2";
SearchMenus.DbCall();
}

if (Pwb.Checked)
{
SearchMenus.SqlCat1 = "3";
SearchMenus.SqlCat2 = "3";
SearchMenus.DbCall();
}

if (Microelectronics.Checked)
{
SearchMenus.SqlCat1 = "4";
SearchMenus.SqlCat2 = "4";
SearchMenus.DbCall();
}

}
}
}


Code behind of User Control:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MyNamespace
{
/// <summary>
/// Summary description for tier.
/// </summary>
public class dropdownsearch : System.Web.UI.UserControl
{
SqlConnection SearchConnection;
protected DataSet MyDataSet = new DataSet();
public DropDownList TradeNames, Applications, Processes;
public Label MyLabel;
private string _SqlCat1;
private string _SqlCat2;

public string SqlCat1
{

get
{
return _SqlCat1;
}
set
{
_SqlCat1 = value;
}
}

public string SqlCat2
{

get
{
return _SqlCat2;
}
set
{
_SqlCat2 = value;
}
}

private void Page_Init(object sender, System.EventArgs e){

}

private void Page_Load(object sender, System.EventArgs e)
{
}

public void DbCall()
{
SearchConnection = new SqlConnection("Server=localhost;uid=sa;password=;database=db");
string MySqlStatement = "sp_DropDownsSql " +SqlCat1+", "+SqlCat2;
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySqlStatement, SearchConnection);
MyAdapter.Fill(MyDataSet);

TradeNames.DataSource = MyDataSet.Tables["Table"];
TradeNames.DataBind();

Applications.DataSource = MyDataSet.Tables["Table1"];
Applications.DataBind();

Processes.DataSource = MyDataSet.Tables["Table2"];
Processes.DataBind();

SearchConnection.Close();
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

}
}

Thanks