Recent Posts

Thursday, December 10, 2009

How to post data to other site via "Post" in

If you need to post data to some other website or URL via post method then this article is the perfect solution.
This article references to the article provided in

I just followed the article and did it in vb. You can click on above link to get the c# code.

As per the above article

Possible Solutions

  1. One possible solution to this problem is to Create your own form control and use it on page this will allow you to change action of form, but again what if you do not want some existing input elements in current page to go to post.
  2. There is good way to post form data using HttpWebResponse & HttpWebRequest class if you want to post data behind the scenes, but if you want to post data using user browser then you are stuck

We have solved this by following way:

Create a RemotePost class (responsible for doing the job) as below:

Public Class RemotePost
Private Inputs As System.Collections.Specialized.NameValueCollection = _
New System.Collections.Specialized.NameValueCollection

Public URL As String = ""
Public Method As String = "post"
Public FormName As String = "form1"

Public Sub Add(ByVal name As String, ByVal value As String)
Inputs.Add(name, value)
End Sub

Public Sub Post()

Dim i As Int16
'System.Web.HttpContext.Current.Response.Write(String.Format("", FormName))
'System.Web.HttpContext.Current.Response.Write(String.Format("", FormName, Method, URL))




Dim str As String
For i = 0 To Inputs.Keys.Count - 1
str = Inputs.Keys(i)
str = Inputs(Inputs.Keys(i))
str = "input name="" type="" value=""" '(Note: put the <> tags)




End Sub

End Class

Now The posting Page which has a linkbutton

asp:LinkButton id="lnkbtnSmartTickets" Runat="server" >test post< /asp:LinkButton

And the code looks like below:

Private Sub lnkbtnPostThis_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim myRemotePost As New RemotePost
myRemotePost.URL = "Receiver.aspx"
myRemotePost.Add("param1", "this is prateek 1")
myRemotePost.Add("param2", "this is regmi2")

End Sub

Now Receiver.aspx will have following code on its form load

If Not Request.Form("param1") = Nothing Then
Response.Write("param1: " & Request.Form("param1"))
End If
If Not Request.Form("param2") = Nothing Then
Response.Write("param2: " & Request.Form("param2"))
End If

Read more!

Monday, December 7, 2009

How to fix Error while trying to run project: Unable to start debugging on the web server

I'm running 2 frameworks 2.0 and 1.1. I had to do the following to switch to 1.1.In a dos prompt do the following:
cd c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
aspnet_regiis.exe -u
cd c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
aspnet_regiis.exe -i

Its hectic but its better to create a batch file to run this when ever required

thanks todymcgee

Read more!

Thursday, December 3, 2009

Problems converting string date to Date or Date time in .net

I was having issue publishing my web site in the Server its regional settings were different to mine and my Asp .net website was giving me following error

" String was not recognized as a valid DateTime "

Since it was working fine in my computer and in debugging mode.

It wasted my 2 hours and finally i changed the code to following to solve the problem

dt = New DateTime(Convert.ToInt16(strYr), Convert.ToInt16(strMon), Convert.ToInt16(strDay))

or if date and time both is required then

dt = New DateTime(Convert.ToInt16(strYear), Convert.ToInt16(strMonth), Convert.ToInt16(strDay), Convert.ToInt16(strHr), Convert.ToInt16(strMin), 0)

This would run without error no matter what regional settings is in the server so it is simpe code but pretty handy. Enjoy coding

Read more!