Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Saturday, March 24, 2012

Stripping Needless Data From HttpContext.Current.Request.Form

I found this nice example of printing data to the default printer of the server when the submit button is clicked. But not sure how to strip out the names of the controls, etc.

Here is the code for those interested:

1Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)23 Dim yPos As Single = 2504 Dim leftMargin As Single = ev.MarginBounds.Left5 Dim topMargin As Single = ev.MarginBounds.Top6 Dim printFont = New Font("Arial", 10)78 Dim sb As StringBuilder = New StringBuilder()910 ' Page title and date/time.11 sb.Append("Maintenance Request")12 sb.Append(Environment.NewLine)13 sb.Append("DateTime: " + DateTime.Now.ToString() + Environment.NewLine)1415 ' Iterate submitted form fields and get field names.16 Dim fieldValue As String17 Dim fieldName As String1819 ' Exclude viewstate and submit button.20 For Each fieldName In HttpContext.Current.Request.Form21 Response.Write("Field Name: " & HttpContext.Current.Request.Form(fieldName) & "<br>")22 If fieldName = "__VIEWSTATE" Or fieldName = "Submit" Then2324 Else25 ' Get the field values.2627 fieldValue = HttpContext.Current.Request.Form(fieldName)2829 ' Add the field names and values to the page.30 ' Break the field values into 50 character segments so it will fit on the paper.31 ' Currently, this only accounts for fields of l50 characters or less.32 ' ISSUE: breaks in the middle of words instead of spaces3334 If fieldValue.Length > 100 Then35 sb.Append(fieldName + ": " + fieldValue.Substring(0, 50) + Environment.NewLine)36 sb.Append(" " + fieldValue.Substring(50, 50) + Environment.NewLine)37 sb.Append(" " + fieldValue.Substring(100, fieldValue.Length - 100) + Environment.NewLine)3839 ElseIf fieldValue.Length > 50 Then40 sb.Append(fieldName + ": " + fieldValue.Substring(0, 50) + Environment.NewLine)41 sb.Append(" " + fieldValue.Substring(50, fieldValue.Length - 50) + Environment.NewLine)42 Else43 sb.Append(fieldName + ": " + fieldValue + Environment.NewLine)4445 End If4647 End If4849 Next50 ev.Graphics.DrawString(sb.ToString(), printFont, Brushes.Black, leftMargin, yPos, New StringFormat())5152 End Sub
 
There has to be a better way. Any ideas?
Figured it out. Instead of using HttpContext.Current.Request.Form, I am just using the explicit names of the controls and appending the values to the stringbuilder. If anyone needs help with this, please feel free to contact me.Big Smile

Tuesday, March 13, 2012

Stuck

Ok,

I got this page (with a datagrid on it) that I hit a button on and it opens
a new page (popup). In that popup I have to option to delete the record that
got me there, or change it.. whatever.

Ok when I am done and close the popup and give focus back to the parent
form...

How can I refresh it so that the changes are shown.. or rebind it or
whatever.. how do I tell the form to do something once the child (popup) is
closed?

thanksYou can use "opener" object before closing the popup form.

like opener.MYFORM.submit(); or opener.refresh;
George.

"HalaszJ" <halaszj@.charter.net> wrote in message
news:eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it
opens
> a new page (popup). In that popup I have to option to delete the record
that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup)
is
> closed?
> thanks
You can use "opener" object before closing the popup form.

like opener.MYFORM.submit(); or opener.refresh;
George.

"HalaszJ" <halaszj@.charter.net> wrote in message
news:eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it
opens
> a new page (popup). In that popup I have to option to delete the record
that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup)
is
> closed?
> thanks
You need some Java Script, to reload the grid's page
before closing your popup try :

opener.document.location.href=opener.document.loca tion.href

or

top.opener.navigate(top.opener.document.location.h ref)

Hope this helps

Eduardo

"HalaszJ" <halaszj@.charter.net> wrote in message news:<eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl>...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it opens
> a new page (popup). In that popup I have to option to delete the record that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup) is
> closed?
> thanks
You need some Java Script, to reload the grid's page
before closing your popup try :

opener.document.location.href=opener.document.loca tion.href

or

top.opener.navigate(top.opener.document.location.h ref)

Hope this helps

Eduardo

"HalaszJ" <halaszj@.charter.net> wrote in message news:<eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl>...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it opens
> a new page (popup). In that popup I have to option to delete the record that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup) is
> closed?
> thanks

stuck in the beginning!

Hi!
I tried to create my first ASP .NET application using VBScript, i recenetly installed .NET, i added some controls like a textbox, a button and few labels. When i try to view the web page, only the labels can be seen but not any other controls. When i try to debug it, i get a messadge saying that i need to install some components. Cany anyone help me out? Thank you.First of all, ASP.NET uses VB.NET not VBScript but I assume that it was just a typo on your behalf (confusing ASP and ASP.NET). In order to get it to work you'll need to install ASP.NET on your IIS server, as follows:
1. go to the command prompt (Start, Run, cmd.exe)
2. go to the Windows\Microsoft.NET\Framework\v1.1.4322 folder
3. execute aspnet_regiis.exe /i

In order to do this, make sure the .NET Framework is installed on the system (available through Windows Update or via the MSDN website). I assume you're using IIS to develop ASP.NET apps in this case. To view your pages, save them in the inetpub\wwwroot folder and go to http://localhost/thepage.aspx (replace theplace.aspx of course) to view the result.
Thanks a lot man. This will get me going. And i apologize for the typo. Thanks again.