Saturday, March 24, 2012
Newbie Grid Question
I have a grid with databound columns, which are filled at run time. I
need to add an onlick event to the link button header that will fire a
vb.net sub procedure. This sub procedure will need to be passed the
data field name which is used to fill the column clicked. The data
fields and link button header names are all determined and filled at
run time.
I want to add the onclick event by calling the attributes.add method
when the column is created. My question is, where do I put this
attributes.add method where I will have access to the data field
name? I dont want to do it on the row created event and I dont think
i have access to the columns in the grid databound event. Can anyone
point me in the right direction? I think I may be doing this
incorrectly.
Thanks so muchOn Feb 27, 1:12 pm, "mianiro" <mian...@.gmail.com> wrote:
> Let me explain my situation ...
> I have a grid with databound columns, which are filled at run time. I
> need to add an onlick event to the link button header that will fire a
> vb.net sub procedure. This sub procedure will need to be passed the
> data field name which is used to fill the column clicked. The data
> fields and link button header names are all determined and filled at
> run time.
> I want to add the onclick event by calling the attributes.add method
> when the column is created. My question is, where do I put this
> attributes.add method where I will have access to the data field
> name? I dont want to do it on the row created event and I dont think
> i have access to the columns in the grid databound event. Can anyone
> point me in the right direction? I think I may be doing this
> incorrectly.
> Thanks so much
Ok, so i figued out where to put it. My problem now is how can i get
the data field name used to populate that column'
grid.columns(0).'
Newbie Grid Question
I have a grid with databound columns, which are filled at run time. I
need to add an onlick event to the link button header that will fire a
vb.net sub procedure. This sub procedure will need to be passed the
data field name which is used to fill the column clicked. The data
fields and link button header names are all determined and filled at
run time.
I want to add the onclick event by calling the attributes.add method
when the column is created. My question is, where do I put this
attributes.add method where I will have access to the data field
name? I dont want to do it on the row created event and I dont think
i have access to the columns in the grid databound event. Can anyone
point me in the right direction? I think I may be doing this
incorrectly.
Thanks so muchOn Feb 27, 1:12 pm, "mianiro" <mian...@.gmail.comwrote:
Quote:
Originally Posted by
Let me explain my situation ...
>
I have a grid with databound columns, which are filled at run time. I
need to add an onlick event to the link button header that will fire a
vb.net sub procedure. This sub procedure will need to be passed the
data field name which is used to fill the column clicked. The data
fields and link button header names are all determined and filled at
run time.
>
I want to add the onclick event by calling the attributes.add method
when the column is created. My question is, where do I put this
attributes.add method where I will have access to the data field
name? I dont want to do it on the row created event and I dont think
i have access to the columns in the grid databound event. Can anyone
point me in the right direction? I think I may be doing this
incorrectly.
>
Thanks so much
Ok, so i figued out where to put it. My problem now is how can i get
the data field name used to populate that column??
grid.columns(0).??
Newbie Help
however each time the button is clicked it adds the page to the list of pages in the back button.
so if i press the button 7 times there will be 7 pages under the back button
How can i stop this from happening?Might help if we see a little code.
But sounds to me if the listbox is also getting information from the database, you need to clear the box first.
myListBox.Items.Clear()
Then add everthing to it again, including the new entry.
Zath
what i have is a user enter data into a textfield.
They then hit add and the textfields data is added to the listbox.
I do this several times
Each time i do it if i go to the back button on the web browser it will have a page in it for each
entry.
Can this be fixed with ispostback.
Common - and still a problem
check out this article
http://stevenbey.co.uk/detectingPageRefresh.aspx
HTH
Hi,
Dino Esposito has also written a page refresh detection mechanism last year. Check it out at:Build Your ASP.NET Pages on a Richer Bedrock.
Grz, Kris.
Thursday, March 22, 2012
Newbie in ASP(not advanced by any means)
Secondly, without makin a class is the following code going to do it's purpose and function correctly. I'm taking the userid and password and I want to check against a SQL table called User--All my information in three tables I want to store in Session variables. I'm drawing everything through stored procedures. I would prefer you resond to my actual email address until I'm back at work on Friday(if not dont' worry about it i'll eventually see what you posted back):
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Session("User") = ""
Session("empID") = ""
Session("SuperEmpID") = ""
Session("deptID") = ""
Session("currPeriod") = ""
Session("companyID") = ""
Session("facilityID") = ""
Session("Shift") = 0
Session("userName") = ""
Session("Role") = ""End Sub
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim dataReader As SqlDataReader
Dim strPass, strUser As String'Session("strUser") = txtUserID.Text
strUser = txtUserID.Text
strPass = txtPassword.TextIf strUser = "" Or strPass = "" Then
Response.Redirect("LogIn.aspx")
lblError.Text = "Your UserID or Password were incorrect. Please Try Again!"
End IfSqlCommand1.Parameters.Add(New SqlParameter("@dotnet.itags.org.strUser", strUser))
SqlCommand1.Parameters.Add(New SqlParameter("@dotnet.itags.org.strPass", strPass))'Opens the connection to the DB
SqlConnection2.Open()'Reads the data entered against SQL DB records
dataReader = SqlCommand1.ExecuteReader()While dataReader.Read()
Session("User") = strUser
Session("SuperEmpID") = dataReader.GetString(1).ToString
Session("userName") = dataReader.GetString(2).ToString
Session("Role") = dataReader.GetString(3).ToString
Session("deptID") = dataReader.GetString(4).ToString
End WhiledataReader.Close()
SqlCommand2.Parameters.Add(New SqlParameter("@dotnet.itags.org.deptID", Session("deptID")))
dataReader = SqlCommand2.ExecuteReaderWhile dataReader.Read
Session("companyID") = dataReader.GetString(1).ToString
Session("facilityID") = dataReader.GetString(2).ToString
Session("empID") = dataReader.GetString(4).ToString
Session("deptID") = dataReader.GetString(6).ToString
Session("Shift") = dataReader.GetString(8).ToString
End WhileResponse.Redirect("ReviewInterPersonal.aspx")
dataReader.Close()'Closes Connection to DB
SqlConnection2.Close()
End Sub
much thanks,
jasonThe common method is to use Debug.Write to write out any messages you want. They'll show up in the output below when you run the application in the IDE.
The other thing I noticed is that you are using While loops. If you are only retrieving one row of data, you Simply use
DataReader.Read
Session("companyID) = dataReader.GetString(1).ToString
etc...
and then close it out like you are.
If you are retrieving multiple rows in your dataset, you need to be aware that each time you loop you are overwriting the prior values.
If you really need to store large amounts of data, you should consider using a DataSet with three datatable objects and then storing the DataSet in a Session Variable.
newbie learns ASP.NET
made me wait long time with Create New Web window
Please tell me what wrong.
System configuration:
Platform: Microsoft Windows XP Pro sp2
web server: IIS 5.0
I also create a virtual directory
Please tell me what wrong
ThanksHi,
1. Does this happen every time you create a new web app?
2. which version of Visual Studio and Asp.Net are you using?
3. Do you get any error during this?
++Vijay R
"Dean L. Howen" wrote:
> I try to create a new web application by Microsoft Visual Studio. But it
> made me wait long time with Create New Web window
> Please tell me what wrong.
> System configuration:
> Platform: Microsoft Windows XP Pro sp2
> web server: IIS 5.0
> I also create a virtual directory
> Please tell me what wrong
> Thanks
>
>I try to create a new web application by Microsoft Visual Studio. But it
>made me wait long time with Create New Web window
> Please tell me what wrong.
I have no idea what is wrong. You're supposed to tell us, and then we tell
you how to fix it.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"Dean L. Howen" <coldman@.hotpop.com> wrote in message
news:ubN4OColFHA.1968@.TK2MSFTNGP14.phx.gbl...
>I try to create a new web application by Microsoft Visual Studio. But it
>made me wait long time with Create New Web window
> Please tell me what wrong.
> System configuration:
> Platform: Microsoft Windows XP Pro sp2
> web server: IIS 5.0
> I also create a virtual directory
> Please tell me what wrong
> Thanks
newbie learns ASP.NET
made me wait long time with Create New Web window
Please tell me what wrong.
System configuration:
Platform: Microsoft Windows XP Pro sp2
web server: IIS 5.0
I also create a virtual directory
Please tell me what wrong
ThanksHi,
1. Does this happen every time you create a new web app?
2. which version of Visual Studio and Asp.Net are you using?
3. Do you get any error during this?
++Vijay R
"Dean L. Howen" wrote:
> I try to create a new web application by Microsoft Visual Studio. But it
> made me wait long time with Create New Web window
> Please tell me what wrong.
> System configuration:
> Platform: Microsoft Windows XP Pro sp2
> web server: IIS 5.0
> I also create a virtual directory
> Please tell me what wrong
> Thanks
>
>
>I try to create a new web application by Microsoft Visual Studio. But it
>made me wait long time with Create New Web window
> Please tell me what wrong.
I have no idea what is wrong. You're supposed to tell us, and then we tell
you how to fix it.
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"Dean L. Howen" <coldman@.hotpop.com> wrote in message
news:ubN4OColFHA.1968@.TK2MSFTNGP14.phx.gbl...
>I try to create a new web application by Microsoft Visual Studio. But it
>made me wait long time with Create New Web window
> Please tell me what wrong.
> System configuration:
> Platform: Microsoft Windows XP Pro sp2
> web server: IIS 5.0
> I also create a virtual directory
> Please tell me what wrong
> Thanks
>
Newbie Microsoft VS.net Code Behind Problem
I am using ASP.net with Code Behind for the first time on Visual Studio. I had some problems and questions.
When we create a Web App Project in VS do i need to copy the resx file too?
Actually i made a page. It is now a .aspx file, a .aspx.vb and a .aspx.resx file. I also made a new class in a VB file. when i built the project i found the dll in the bin folder.
I uploaded the stuff onto the web page (all three, global.asax, web.config) and the dll into the bin folder of my websites root, but it doesnt work. I made some changes in my project and rebuilt it, but the changes werent reflected (i added a Response.Write in the Page_Load).
I copied the vb file to the sites root too but the thing doesnt work. Its working perfectly on my localhost.
I also wanted to know that i added the class in the file by choosing Add Class in the projects menu. So its automatically compiled to a dll right? Another thing is that in localhost the site was working in a folder and not directly in wwwroot (in a folder called even). So when i was to import my custom made namespace it was referenced as Even.MyNameSpace, but normally i compile it to a dll and do it directly.
Another thing is that i tried compiling it to a dll. Visual Studio tools and then VS.net Command prompt, followed by vbc /t:library myVbFile.vb but it couldnt compile. It couldnt find the namespace i imported. It cant even import namespaces like System.Xml etc.
Someone please help. Please tell me if i am not clear as this is a very basic problem.Lots of problems and possible issues here. To start with, you'd have to explain what "didn't work" means. Have you tested a very simple Hello World! ASPX file, with no code behind, to make sure you understand the basics of working with VS and your web host?
Jeff
Well I uploaded a file which on clicking over a button shows the contents of an XML file.
I made a namespace and added a class in it to access and XML file. In my pages code behind i use this class to return the data. (the xml contains values coupled together). The class has many function like getData1, getData2 etc.
The Class for reading the XML throws a user created exception (that i made) if no data existed, else it threw the usual exception. This is caught by the page in which i have called the xml reader class. If its the user exception it simply writes that no data was found else it writes the exceptions text. So initially as i said when i uploaded it gave a message written "The remote server returned an error: (404) Not Found." as the exception's message. I then uploaded all the files i mentioned alongwith the assemblyinfo. But it still didnt work. Then i uploaded a new file which had a "page loaded" string in its page_load, but the changes were not affected. I rebuilt the project in VS and then uploaded the new resx, aspx.vb and aspx files, but to no avail.
I have worked on Dreamweaver and without code behind. Later i tried to compile the VB file but the VS .net command prompt compiler gave me that error. My VS by default creates page with code behind only. Can this be changed? Actually i want to create my own class and compile it to a dll and then make the page inherit from the class from the dll.
I have another question. I had named my project even in VS and then started working in the folder even in the wwwroot. Now i uploaded the whole folder onto the site in a folder placed in the root with the same name as even. Made it an IIS application but still the code doesnt run. It started workng after i uploaded the aspnet_client to the even folder.
Can anyone tell me how i can deploy this to my root? Moreover when i change any file what all files do i need to upload again? Is there a way to prevent VS to automatically creating a page behind as i would like to put all my classes into a dll and then use them as page behind. Moreover when i build the project are the .vb files automatically compiled to dll?
I have one basic question. How do we deploy our VS projects to our web site? I am not able to get any file to work on the website. I have no problems at my own computer and everything is working fine. I am sure a lot of people here can teach me how to deploy VS projects? What all changes etc have to be done?
Im no expert here but if you compile this as a release instead of a Debug build and then create a "Web Setup Project" under the New Projects and then choose Setup and Deployment Projects. Then you can "install" the website to your webserver.
Cleako
I just noticed another thing in your post. If you are going to want your classes in a DLLs separate from the main project then you need to create a class library and place all of your classes that you would like to keep separate in there and then just create instances of those classes within the library in the other project.
Cleako
As you suggested i created a class library. Then i made a file in some Namespace and put in a class. After building it i copied the dll from the bin folder to my sites bin folder. But still i couldnt use the class in my aspx pages. If i compile the same class through command line
vbc /t:library /out:MyClass.dll SomeClass.vb
then it works.
Moreover one of my classes had Imports System.Xml in it. when i build it, it works but when i use the above command line statement in the VS.net Command prompt i get an error saying the file couldnt be found. I dont know what to do and am stuck.
I tried adding the class library to my project, but still cant use it. How do other people generally implement code behind without using VS? I want to create classes in VS but use them in my aspx pages which i make in Dreamweaver.
Friday, March 16, 2012
Newbie needs help
I have been developing with ASP 3.0 and VB6 for the past few years and I decided it was finally time to learn .NET. I have recently purchased VB.NET and I am running on a win2k adv server box using Access 2002 as a back end (I am working on aquiring SQL Server). I am attempting to test my first code in ASP.NET but I am having difficulties. I am hoping somebody may be able to point me in the correct direction. The code I am using is posted below.
<HTML>
<HEAD>
<title>WebForm1</title>
<script language="vb" runat="server">
Sub Page_OnLoad(sender as Object, e as EventArgs)
Response.Write("called")
Dim strConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\inetpub\wwwroot\webapp1\db1.mdb;"Dim objConn as New OleDbConnection(strConnString)
Dim strSQL as String = "SELECT * FROM Names"
Dim objCmd as new OleDbCommand(strSQL, objConn)MyDataGrid.DataSource = objCmd.ExecuteReader
MyDataGrid.DataBind()
End SubSub MyButton_OnClick(Sender as Object, e as EventArgs)
Response.Write("called")
End Sub
</script>
</HEAD>
<body>
<form name="frmTest" runat="server">
<asp:Button ID="MyButton" Runat="server" Text="Click Me" />
<asp:DataGrid ID="MyDataGrid" Runat="server" BorderColor=#ff00ff />
</form>
</body>
</HTML>
For some reason when I view this .aspx page the datagrid doesn't show up and neither does the data access portion. Coming from an ASP 3.0 background my first instinct was to place the "response.write" command in the page_load sub to see if that sub was being called correctly. None of the above shows up on the page. However, if I place a plain text box or button it shows up fine. I have searched the forums here and found a few posts that had a similar problem, so I ran the aspnet_regiis -i from the cmd prompt and it installed correctly, but it didn't help my problems any. I also made sure that IIS has this set up as an application. Being new to .NET I am not sure where to go from here and would appreciate any feedback on how to fix this issue.
Regards,
Coreywell the first thin I see is that you are using Page_OnLoad which is incorrect, it is Page_Load. Also you have not opened the connection so just add this before you define your sql string
objConn.Open()
then after you you bind the data, make sure you close the connection using
objConn.Close()
That should solve the problem
Hi,
first off all: response.write was used a lot in classic asp but in asp.net it's nicer to use trace.write (or trace.warn). Make sure that tracing is enabled for the page.
You're probably using webmatrix as a tool so it's better to check out theguided tour first.
Grz, Kris.
Thanks for the replies. I began to experiment with the code behind files and finally figured out that my problem was with the name of my db table name. It was a reserved word and when I surrounded it by "[ ]" it began working properly.
Regards,
Corey
Newbie needs help with Rounding Time
I need the current Military time (ex 906 equals 9:06) rounded to the nearest ten. So I need ten minute increments. Instead of 906 I need 910, and instead of 903 I need 900. I've tried the using the System.Math.Round function but it only takes decimals and it doesn't round whole numbers.
Any help would be greatly appreciated!!
Thanks,
Chris
Hi Chris,
Here's a start. This code rounds military time to the nearest ten. Modify the last line if you need the output in a different format.
string timeStr = "2259";
timeStr = timeStr.Insert(timeStr.Length-2,":");
DateTime nowTime = Convert.ToDateTime(timeStr);
decimal dTimeMin = Convert.ToDecimal(nowTime.Minute);
decimal dMinRound = dTimeMin / 10;
dMinRound = System.Math.Round(dMinRound);
dMinRound = dMinRound * 10;
double diffVal = (int)dMinRound - (int)dTimeMin;
DateTime myResult = nowTime.AddMinutes(diffVal);
Response.Write(myResult.TimeOfDay.ToString());
Hope this helps.
-- Erik Reitan
ASP.NET User Education
This posting is provided "AS IS" with no warranties, and confers no rights.
Newbie needs some help.
My goal was, and still is, to create a webstore. Not an higly complex one, nor a simple one.
So a middle-of-the-road webstore it should be. Coming to the point now:
I've created a database with the needed fields in it. Then wrote a page which, via buttons, shows the information asked in a datagrid where one column has hyperlinks directing to a detail-page. That page shows the specific article with its details and some things to be filled in by the user (dropdownlist, textbox, etc...) as a datalist.
So far so good, and that's where it ends too, because I don't know how to proceed. What I'd like to have is a button in the deatil-page which will be able to hold the selected and filled in info and will be stored in some kind of basket/shoppingcart (lets say: basket.aspx or something like that). Finally I'd like to have a page where all the items ordered by the user show up and where the user would be able to order the things he choose.
I know this can be done by using controls given in the controlgallery, but for I am a newbie I'd like to try to do it on my, so that I understand what I'm doing and what the code is doing.
Then I've got a second question: is it a good decision to buy the book ASP.NET Unleahed?
Any help would be appreciated
Thanks in advance
PosNRG.Chapter 31 ofASP.NET Unleashed walks you through creating an Online Store, complete with a shopping cart.
I cannot say enough good things about this book. (And it is often recommended on this forum.)
So, if you buy it, you will find the answer to your question, and learn more in doing so than we could ever teach you in a forum.
Thank you for your time and your quick response SomeNewKid2.
Buying the book is the first thing I'll do.
Regards,
PosNRG