Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts

Thursday, March 29, 2012

Popping up a window

Hi,

I'm writing a page in asp.net to post something to a website and I'm trying to add a preview button to the page. The problem with the code lies in popping up a window containing the preview. The onClick event of the asp:button runs a subroutine to create a new text file, 'temp.txt' (using a Try... Catch statement). Once this is done, I have added the following line:
message.Text = "<script language=Javascript>window.open('disp_report.asp?temp.txt');</script>", where message is an asp:label. This results in a Compilation Error saying 'Try statement must end with an 'End Try', almost as if the line of code was an unterminated string. Commenting out the line (with a ') results in the same error.

Any ideas?Can you post your code as you have it in the IDE?
How much do you want? The whole page?
Here's the page (attached). The line of code I mentioned is commented out at the bottom of the Preview_Click subroutine. It still causes the error, though. For the moment, I've got the message label showing a hyperlink to view the preview, which is a bit messy, but works.
I cant get the attachment, says invalid. Can you make it a textfile?
Done before you posted ;)
Ah, ok. I was getting the forums source for this page :lol:
Let me see what you got now.
I edited the post with the aspx attachment, removed that and added the text file instead.
Don't set the label's text to that script.

To popup a window, in the button's click event, after generating the file, do this:

Page.RegisterStartupScript("script1","<script language=Javascript>window.open('disp_report.asp?temp.txt');</script>")

That is the way to do it.
Thanks for helping froggy. I was stuck on this.

I fed you earlier so you'll have to wait for the next mealtime. :D
In case you haven't noticed by now, I like microwaved cheese sandwiches :afrog:
Thanks for that.

How do I then remove the Startup script so that it doesn't fire again when they click Save?
No, that hasn't worked... still giving me the same error.

Putting it outside of the Try statement throws up:
'BC30648: String constants must end with a double quote.'

And the calendar control keeps going Italian on me!
Okay, building up the string gradually has shown that the problem seems to be with the final ">". However,
Dim strScript As String
strScript = "<script language=Javascript>window.open('disp_report.asp?temp.txt');</script" & ">"
Page.RegisterStartupScript("script1", strScript) seems to work.

Weird...

This still isn't giving me a popup, either. Searching the page source after the button has been clicked shows that the script is there, right after the 'Temporary match report created...' on the page. Any more ideas?

**Edit**

Turns out, the popup works fine - Norton Internet Security is just blocking it! Any way round this? I'm still having the Italian calendar problem, too.
Any popup blockers in place?
Norton Internet Security is the culprit. Is there any way round this? I can add an exception on my computer, but it's not really feasible for everyone visiting using Norton to do.

I'm still getting the Italian calendar from time to time, too!
For the first part, do you really need the popup to open when the page reloads, or can you have it when the user clicks on the link? Things could be easier if it's on the link click.

For the second part, how Italian is it? Is it romancing you?
Well, it would look better if the page popped up, but it's not essential.

As for the calendar, I've attached an image.
Oh, it's going Italian on you, literally.

I thought you were using a cliche or euphemism for "It's trying to kill me." :sick:

For the calendar, check your regional settings in Control Panel.
My regional settings are fine. It's just bizarre that the calendar control is only sometimes Italian... It's something like 1 time in 5 that it appears like that!

**Edit**

The following lines of code seem to have fixed it:

Sub Page_Load()
Dim lang As System.Globalization.CultureInfo
lang = New System.Globalization.CultureInfo("en-gb")
System.Threading.Thread.CurrentThread.CurrentCulture = lang
System.Threading.Thread.CurrentThread.CurrentUICulture = lang
End Sub

Back to the original question - can you think of a reason why I had to concatenate on the last '>' like that?
No, I can't think of any. You shouldn't even have to do that. It maybe a simple double quote problem that we're overlooking.
Dont you need to use the escape char when using the "/"?
Not for asp.net, surely? It should treat everything within the quotation marks as a string literal and that's it...
The escape characters would be in use in C# codebehind, but he's got VB.NET there.
Dont you need the escpae char for the JavaScript is what I was meaning.
If it were in the javascript code itself, yes. :D
Well, I suppose I should mark this resolved. We got the popup going, although no resolution about that last '>'. I've actually seen that in some code before - where it's added on at the end, but there was no explanation as to why. I just thought, 'that looks pointless...' and left it at that.

Wednesday, March 21, 2012

Populating a datagrid ... how is it done normally?

Hi All ...
I'm writing a small shopping cart app (school assignment) and need to list
all the books that a user selects.
I have created a "BookBasket" object that contains among other things an
arraylist of the user selected books. The "book" object contains isbn,title
price and quantity information.
I'd like to display the contents of the BookBasket in a datagrid control.
I assume that to start with I'd have to iterate through the basket to
identify each books information, but then how do I populate the datagrid
from there?
It seems from what I've read,that it is easier to populate a datagrid from a
datasource, but I don't know how that would relate to what I'm doing.
any clues or links to examples would be much appreciated.
Thanks in advance
Prime.Prime,
There is a plethora of examples on using a datagrid control. Search
google and you will find more than you need. The second article outlines
what kind of datasources a datagrid will accept, an array is a valid data
source so you won't have to write any code to fill another control. The
third snippit supports my last statement.
Hope this helps.
Jared
Here's one to get you started
http://samples.gotdotnet.com/quicks...c_datagrid.aspx
http://msdn.microsoft.com/library/d...nadodataset.asp
You can bind to the following structures if their elements expose public
properties:
a.. Any component that implements the IList interface. This includes
single-dimension arrays
"Prime" <not@.real.address> wrote in message
news:uIhFN$0pEHA.1668@.TK2MSFTNGP14.phx.gbl...
> Hi All ...
> I'm writing a small shopping cart app (school assignment) and need to list
> all the books that a user selects.
> I have created a "BookBasket" object that contains among other things an
> arraylist of the user selected books. The "book" object contains
> isbn,title
> price and quantity information.
> I'd like to display the contents of the BookBasket in a datagrid control.
> I assume that to start with I'd have to iterate through the basket to
> identify each books information, but then how do I populate the datagrid
> from there?
> It seems from what I've read,that it is easier to populate a datagrid from
> a
> datasource, but I don't know how that would relate to what I'm doing.
> any clues or links to examples would be much appreciated.
> Thanks in advance
> Prime.
>
>
Hi Jared,
I think you've helped me before ... thank-you again.
I found the gotdotnet sample very helpful. We are currently using a text
book that is poor by any standard so your assistance is very much
appreciated.
The second sample was good, but we're not allowed to use a database
interface! I originally coded my app that way,but was told that it was
unacceptable. :( I found the database version extremely simple to code.)
Again, thanks for you assistance.
Prime.
"Jared" <ask_me_for_it@.nospam.com> wrote in message
news:10lpaldc1uahra6@.corp.supernews.com...
> Prime,
> There is a plethora of examples on using a datagrid control. Search
> google and you will find more than you need. The second article outlines
> what kind of datasources a datagrid will accept, an array is a valid data
> source so you won't have to write any code to fill another control. The
> third snippit supports my last statement.
> Hope this helps.
> Jared
> Here's one to get you started
>
http://samples.gotdotnet.com/quicks... />
agrid.aspx
>
http://msdn.microsoft.com/library/d...nadodataset.asp
> You can bind to the following structures if their elements expose public
> properties:
> a.. Any component that implements the IList interface. This includes
> single-dimension arrays
> "Prime" <not@.real.address> wrote in message
> news:uIhFN$0pEHA.1668@.TK2MSFTNGP14.phx.gbl...
list
control.
from
>

Populating a datagrid ... how is it done normally?

Hi All ...

I'm writing a small shopping cart app (school assignment) and need to list
all the books that a user selects.

I have created a "BookBasket" object that contains among other things an
arraylist of the user selected books. The "book" object contains isbn,title
price and quantity information.

I'd like to display the contents of the BookBasket in a datagrid control.

I assume that to start with I'd have to iterate through the basket to
identify each books information, but then how do I populate the datagrid
from there?

It seems from what I've read,that it is easier to populate a datagrid from a
datasource, but I don't know how that would relate to what I'm doing.

any clues or links to examples would be much appreciated.

Thanks in advance

Prime.Prime,
There is a plethora of examples on using a datagrid control. Search
google and you will find more than you need. The second article outlines
what kind of datasources a datagrid will accept, an array is a valid data
source so you won't have to write any code to fill another control. The
third snippit supports my last statement.
Hope this helps.
Jared

Here's one to get you started
http://samples.gotdotnet.com/quicks...c_datagrid.aspx

http://msdn.microsoft.com/library/d...nadodataset.asp

You can bind to the following structures if their elements expose public
properties:

a.. Any component that implements the IList interface. This includes
single-dimension arrays

"Prime" <not@.real.address> wrote in message
news:uIhFN$0pEHA.1668@.TK2MSFTNGP14.phx.gbl...
> Hi All ...
> I'm writing a small shopping cart app (school assignment) and need to list
> all the books that a user selects.
> I have created a "BookBasket" object that contains among other things an
> arraylist of the user selected books. The "book" object contains
> isbn,title
> price and quantity information.
> I'd like to display the contents of the BookBasket in a datagrid control.
> I assume that to start with I'd have to iterate through the basket to
> identify each books information, but then how do I populate the datagrid
> from there?
> It seems from what I've read,that it is easier to populate a datagrid from
> a
> datasource, but I don't know how that would relate to what I'm doing.
> any clues or links to examples would be much appreciated.
> Thanks in advance
> Prime.
>
Hi Jared,

I think you've helped me before ... thank-you again.

I found the gotdotnet sample very helpful. We are currently using a text
book that is poor by any standard so your assistance is very much
appreciated.

The second sample was good, but we're not allowed to use a database
interface! I originally coded my app that way,but was told that it was
unacceptable. :( I found the database version extremely simple to code.)

Again, thanks for you assistance.

Prime.

"Jared" <ask_me_for_it@.nospam.com> wrote in message
news:10lpaldc1uahra6@.corp.supernews.com...
> Prime,
> There is a plethora of examples on using a datagrid control. Search
> google and you will find more than you need. The second article outlines
> what kind of datasources a datagrid will accept, an array is a valid data
> source so you won't have to write any code to fill another control. The
> third snippit supports my last statement.
> Hope this helps.
> Jared
> Here's one to get you started
http://samples.gotdotnet.com/quicks...c_datagrid.aspx
>
http://msdn.microsoft.com/library/d...nadodataset.asp
> You can bind to the following structures if their elements expose public
> properties:
> a.. Any component that implements the IList interface. This includes
> single-dimension arrays
> "Prime" <not@.real.address> wrote in message
> news:uIhFN$0pEHA.1668@.TK2MSFTNGP14.phx.gbl...
> > Hi All ...
> > I'm writing a small shopping cart app (school assignment) and need to
list
> > all the books that a user selects.
> > I have created a "BookBasket" object that contains among other things an
> > arraylist of the user selected books. The "book" object contains
> > isbn,title
> > price and quantity information.
> > I'd like to display the contents of the BookBasket in a datagrid
control.
> > I assume that to start with I'd have to iterate through the basket to
> > identify each books information, but then how do I populate the datagrid
> > from there?
> > It seems from what I've read,that it is easier to populate a datagrid
from
> > a
> > datasource, but I don't know how that would relate to what I'm doing.
> > any clues or links to examples would be much appreciated.
> > Thanks in advance
> > Prime.

Populating a DB from a DropDownList Control

Good afternoon. I'm in the midst of writing up a pretty "basic" web
form and having some difficulties. I'm completely open for
suggestions. I'm using VS.net 2003, and what iwould like to accomplish
is to have a form with two dropdown Boxes a button and a datagrid to
display what was selected from the drop downs. One of the drop downs
values can not be used more than once while the others can be repeated
as often as they like. Being that I'm a somewhat new developer I'm
finding even the easiest tasks to be difficult. The DropDownBoxes are
server controls that I pre-populated from in the aspx html. These
values will change very infrequently, so editing the aspx to add more
shouldn't be a problem. The problem that I'm having is that I can not
get any values to show in the Data Grid. These values must also be
stored in a DB that I created. I'm on what Data Controls I
would need, how to configure them. I have a SQLConnection control and
it is, to my belief able to connect to the DB. I have also read to
have a SQLCommand control and a SQLDataAdapter control. Any assistance
is greatly appreciated. Thanks, WillTry this.
Dim myConn as SqlConnection = New SqlConnection(Connection string)
Dim myDa as SqlDataAdapter = new SqlDataAdapter("Select query", myConn)
myConn.Open()
Dim myDs as DataSet = New DataSet
myDa.Fill(Ds, "All") '{populate Dataset with data
'Bind data to datagrid
datagrid1.DataSource = Ds
datagrid1.DataBind()
wcaruso welcome to the forum..
Try looking at this sample at:-
http://aspnet101.com/aspnet101/aspn...e.aspx?code=md2
It should guide you.
Also try seeing through quickstart at:-
http://asp.net/Tutorials/quickstart.aspx
Hope that helps
Patrick
<wcaruso@.gmail.com> wrote in message
news:1130962262.235096.310430@.g44g2000cwa.googlegroups.com...
> Good afternoon. I'm in the midst of writing up a pretty "basic" web
> form and having some difficulties. I'm completely open for
> suggestions. I'm using VS.net 2003, and what iwould like to accomplish
> is to have a form with two dropdown Boxes a button and a datagrid to
> display what was selected from the drop downs. One of the drop downs
> values can not be used more than once while the others can be repeated
> as often as they like. Being that I'm a somewhat new developer I'm
> finding even the easiest tasks to be difficult. The DropDownBoxes are
> server controls that I pre-populated from in the aspx html. These
> values will change very infrequently, so editing the aspx to add more
> shouldn't be a problem. The problem that I'm having is that I can not
> get any values to show in the Data Grid. These values must also be
> stored in a DB that I created. I'm on what Data Controls I
> would need, how to configure them. I have a SQLConnection control and
> it is, to my belief able to connect to the DB. I have also read to
> have a SQLCommand control and a SQLDataAdapter control. Any assistance
> is greatly appreciated. Thanks, Will
>

Populating a DB from a DropDownList Control

Good afternoon. I'm in the midst of writing up a pretty "basic" web
form and having some difficulties. I'm completely open for
suggestions. I'm using VS.net 2003, and what iwould like to accomplish
is to have a form with two dropdown Boxes a button and a datagrid to
display what was selected from the drop downs. One of the drop downs
values can not be used more than once while the others can be repeated
as often as they like. Being that I'm a somewhat new developer I'm
finding even the easiest tasks to be difficult. The DropDownBoxes are
server controls that I pre-populated from in the aspx html. These
values will change very infrequently, so editing the aspx to add more
shouldn't be a problem. The problem that I'm having is that I can not
get any values to show in the Data Grid. These values must also be
stored in a DB that I created. I'm confused on what Data Controls I
would need, how to configure them. I have a SQLConnection control and
it is, to my belief able to connect to the DB. I have also read to
have a SQLCommand control and a SQLDataAdapter control. Any assistance
is greatly appreciated. Thanks, WillTry this.

Dim myConn as SqlConnection = New SqlConnection(Connection string)
Dim myDa as SqlDataAdapter = new SqlDataAdapter("Select query", myConn)

myConn.Open()
Dim myDs as DataSet = New DataSet

myDa.Fill(Ds, "All") '{populate Dataset with data

'Bind data to datagrid
datagrid1.DataSource = Ds
datagrid1.DataBind()
wcaruso welcome to the forum..
Try looking at this sample at:-
http://aspnet101.com/aspnet101/aspn...e.aspx?code=md2
It should guide you.
Also try seeing through quickstart at:-
http://asp.net/Tutorials/quickstart.aspx
Hope that helps
Patrick

<wcaruso@.gmail.com> wrote in message
news:1130962262.235096.310430@.g44g2000cwa.googlegr oups.com...
> Good afternoon. I'm in the midst of writing up a pretty "basic" web
> form and having some difficulties. I'm completely open for
> suggestions. I'm using VS.net 2003, and what iwould like to accomplish
> is to have a form with two dropdown Boxes a button and a datagrid to
> display what was selected from the drop downs. One of the drop downs
> values can not be used more than once while the others can be repeated
> as often as they like. Being that I'm a somewhat new developer I'm
> finding even the easiest tasks to be difficult. The DropDownBoxes are
> server controls that I pre-populated from in the aspx html. These
> values will change very infrequently, so editing the aspx to add more
> shouldn't be a problem. The problem that I'm having is that I can not
> get any values to show in the Data Grid. These values must also be
> stored in a DB that I created. I'm confused on what Data Controls I
> would need, how to configure them. I have a SQLConnection control and
> it is, to my belief able to connect to the DB. I have also read to
> have a SQLCommand control and a SQLDataAdapter control. Any assistance
> is greatly appreciated. Thanks, Will