Saturday, March 31, 2012

Submitting a web form to a web server from a running windows servive.

hi and help. i have a windows service, in wich i want to submite a web from to a web server with some hidden fiels. how do i do this. and afterwords how can i get response from web server in windows service.
----------
From: Muhammad Saifullah

--------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>i6K//UAKUk2P/CaV2/rNFA==</Id>look up HttpWebRequest

Submitting a web form to a web server from a running windows servive.

hi and help. i have a windows service, in wich i want to submite a web from
to a web server with some hidden fiels. how do i do this. and afterwords how
can i get response from web server in windows service.
--
From: Muhammad Saifullah
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>i6K//UAKUk2P/CaV2/rNFA==</Id>look up HttpWebRequest

submitting a PDF form

I have a pdf form with form fields. I want to submit the values and post them to a database. I created a save button and the action is "Submit form". It calls an aspx file. When I try to write out the request variables I get none. For some reason none are getting posted. What am i doing wrong?
I have been trying to figure this out for quite some time and I am getting a bit frustrated, any help would be greatly appreciated.
Thanks.Code would be useful. What does the command look like that's attempting to write to the db? Is the information supplied to gain access to the db correct? Are the table/field names correct? Is your syntax correct?
The reason that I didnt bother posting any code is because I am getting stuck before the point that I try to put the info into the db. I cant even retrieve the form variables
Request.form("name of filed from pdf form")
this value gives me nothing.
My question is if there is something that I am supposed to be doing in the PDF form that should make this work.
thanks.
http://www.tgreer.com/pdfSubmit.html

Submitting data to sql

I am new to asp.net. I was wondering if some one can help be out with something
this is what I have for my submit button
Me.txtprocess.Text.Insert()

all I am trying to do is when a user puts an entry in and click submit the entry is written over to a sql table.

Thanks in advanceJust do something like...

Dim strSQL As String ' SQL Statement
Dim cmd As New SqlClient.SqlCommand ' SQL Command
Dim strSubject As String ' Subject String

' Set the SQL connection to use for SQL Command
cmd.Connection = New SqlClient.SqlConnection("Persist Security Info=False;server=MyServer;database=MyDB;User ID=sa;Password=MyPassword")

' Add neccessary parameters to the SQL Command
cmd.Parameters.Add("@.MyData", txtMyData.Text)

' SQL UPDATE Statement
strSQL = "INSERT INTO MyTable (MyColumn) Values (MyData)"

' Try to catch any exceptions
Try
' if the SQL Connection is closed, open it
If SqlConn.State = ConnectionState.Closed Then
SqlConn.Open()
End If

' Set the SQL Command SQL Statement
cmd.CommandText = strSQL

' Execute the SQL Insert or Update
cmd.ExecuteNonQuery()

' Catch any exceptions
Catch ex As Exception

' Finally if it excepts or not
Finally
' If the SQL Connection is open, close it
If SqlConn.State = ConnectionState.Open Then
SqlConn.Close()
End If

End Try

Submitting Data to Another Page Using ASP.NET

I need to post an ASP.NET form between sites for report processing.
Site A contains the asp.net forms and site B contains Java Servlets for
report processing.

All form fields values must be passed to the reporting servlet via http
post method. No parameters can be transmitted by URL. The report must
display in a NEW browser window. Does anyone know how to set a target
using httpwebrequest or is there another alternative?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Hi Dennis,

I've had success doing that using the Webclient class. You need to know
exactly what form field names the target expects.

Not sure about setting it to open in a new page.

Anyway, here's some code to give you an idea:

Sub DoPost()
Dim uriString As String = _
"http://localhost/p4320work/mySpecialPage.aspx"
Dim strGoName As String
strGoName = TextBox1.Text
' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient
Dim myNameValueCollection As New _
System.Collections.Specialized.NameValueCollection
myNameValueCollection.Add("go1", strGoName)
myNameValueCollection.Add("Button1", "")
Dim responseArray As Byte() = myWebClient.UploadValues _
(uriString, "POST", myNameValueCollection)
' Response.Redirect("http://msdn.microsoft.com/")
End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Call DoPost()
End Sub

<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBox1" runat="server">test</asp:TextBox></P>
<P>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
</form
Ken
Microsoft MVP [ASP.NET]
Toronto

<Dennis E. Jones>; "Jr." <djone2@.jcpenney.com> wrote in message
news:e1jFoNTCFHA.520@.TK2MSFTNGP09.phx.gbl...
>I need to post an ASP.NET form between sites for report processing.
> Site A contains the asp.net forms and site B contains Java Servlets for
> report processing.
> All form fields values must be passed to the reporting servlet via http
> post method. No parameters can be transmitted by URL. The report must
> display in a NEW browser window. Does anyone know how to set a target
> using httpwebrequest or is there another alternative?
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Yes, that works...but I still need a solution for the target attribute.
Thanks for your help.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
If all you want is a submit button that opens your servlet in a new
window, .NET never comes into play:

<form action="yourServlet.jsp" target="_blank" method="post">
<input type=...>
<input type="submit">
</form
Retarget your form from the HTML side.
Jason
http://www.expatsoftware.com
If I do not use .NET, then my server controls also go away....I guess a
javascript injected into the page on postback would work, but only for
those browsers that support Javascript.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Submitting Data to Another Page Using ASP.NET

I need to post an ASP.NET form between sites for report processing.
Site A contains the asp.net forms and site B contains Java Servlets for
report processing.
All form fields values must be passed to the reporting servlet via http
post method. No parameters can be transmitted by URL. The report must
display in a NEW browser window. Does anyone know how to set a target
using httpwebrequest or is there another alternative?
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!Hi Dennis,
I've had success doing that using the Webclient class. You need to know
exactly what form field names the target expects.
Not sure about setting it to open in a new page.
Anyway, here's some code to give you an idea:
Sub DoPost()
Dim uriString As String = _
"http://localhost/p4320work/mySpecialPage.aspx"
Dim strGoName As String
strGoName = TextBox1.Text
' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient
Dim myNameValueCollection As New _
System.Collections.Specialized.NameValueCollection
myNameValueCollection.Add("go1", strGoName)
myNameValueCollection.Add("Button1", "")
Dim responseArray As Byte() = myWebClient.UploadValues _
(uriString, "POST", myNameValueCollection)
' Response.Redirect("http://msdn.microsoft.com/")
End Sub
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Call DoPost()
End Sub
<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBox1" runat="server">test</asp:TextBox></P>
<P>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
</form>
Ken
Microsoft MVP [ASP.NET]
Toronto
<Dennis E. Jones>; "Jr." <djone2@.jcpenney.com> wrote in message
news:e1jFoNTCFHA.520@.TK2MSFTNGP09.phx.gbl...
>I need to post an ASP.NET form between sites for report processing.
> Site A contains the asp.net forms and site B contains Java Servlets for
> report processing.
> All form fields values must be passed to the reporting servlet via http
> post method. No parameters can be transmitted by URL. The report must
> display in a NEW browser window. Does anyone know how to set a target
> using httpwebrequest or is there another alternative?
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
Yes, that works...but I still need a solution for the target attribute.
Thanks for your help.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
If I do not use .NET, then my server controls also go away....I guess a
javascript injected into the page on postback would work, but only for
those browsers that support Javascript.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!

Submitting form doesnt update .Text

Hi!
I have this form that I use, both for adding records and for updating. When submitted, it checks if the Reuqest.Querystring("pid") i set, if not it adds a new record, otherwise it should update the current record (based on pid).
There are no problems if I add a record, but on update, the values in the form doesn't follow.
The basic structure is this:

Sub saveNews(Byval id)
'When I use this on an update, the values in name.Text and pbody.Text aren't the ones entered, but the previous values in the textboxes (or database).
If id <>""Then'Update dbElse'Add new recordEnd IfEnd SubSub btnSave()Call saveNews(Request.Querystring("pid")End Sub

Sub fEditFrm(ByVal id)
'Here I fetch the columns based on id
If objDR.HasRows Then
pbody.Text = objDR("pbody")
name.Text = objDR("name")
date_created.Text = objDR("date_created")
End If
End Sub

Sub Page.Load()'This checks which page you're onSelect Case Request.Querystring("page")Case"addnew" news.SetActiveView(editnews)Case"edit" news.SetActiveView(editnews)Call fEditFrm(Request.QueryString("pid"))'This one fetches the record and populates the textboxesEnd Sub


Is my problem understandable at all?
Thanks you alot!
/MartinI found the problem. Apparently the sub fEditFrm (which populate the form with db entry) executes before the update in saveNews(), so the textboxes reverted to the original values... I added an 'If Not Page.IsPostback' before the Call fEditFrm and it worked.
But then I have another question:
How can you check in which order things are executed? I come from classic ASP and it wasn't too hard to do things like this. Btw, I'm using VWD Express edition.

Enable tracing on the Page...

<%#@. Page Trace="true" TraceMode="SortByTime"%>

Then run the page. At the bottom you will see everything that is going on inside the page.


Thanks!
That was very useful, in Classic ASP I have this subroutine that spits out that info but this was much easier :)

Question though; is it possible to put that trace into a master page so you don't have to edit every single page?

Thanks again!
/Martin

You can enable trace for all pages in the web.config file, which looks something like this:

<configuration><web.config><trace enabled="true" traceMode="SortByTime" localOnly="false" /></web.config></configuration>

Thanks alot! I'll try it as soon as it's possible!