Programmatically Posting Data to ASP .NET Web Applications

Usually what we do. We open a page and fill up a form and submit a form data by pressing “Submit” Button. And after that we get some data/response  as per the logic.  But how to do this programmatically?? — That’s what we have been doing since so long..we faced too many challenges and finally we made it working. You also want to do the same then here we go…
First follow this nice article :
http://dotnet.sys-con.com/node/45127
if you follow all the steps and also COPY-PASTE the whole code given below:
http://gemsres.com/photos/story/res/45127/source.html
IT WON’T WORK
As someone has already commented on that post — That it throws Internal Server Error(500). But unfortunately no solution has been answered. But don’t worry. i’m here to answer that 🙂
Okay, The problem is in your target ASPX page — Means ASPX Page which has form tag. it should have event validation false:

<%@ Page EnableEventValidation=”false” %>

That’s it. It should work now. And if it dosen’t works then try to debug using Fiddler — Really great tool
Okay, So in short to post form data programmatic ally using ASP.NET following steps are required.
1. ViewState Must be passed.
2. In Target page — enableeventvalidation – false.
3. Fiddler must need to install to see what’s going on 🙂
Webliography
http://xneuron.wordpress.com/2007/12/05/programmatically-post-a-form-in-aspnet/
http://schleichermann.wordpress.com/2009/07/13/asp-net-programmatically-submit-form-post/
Hope this helps 🙂

There is no script engine for file extension “.vbs”

Challenge:

If you received an error saying There is no script engine for file extension “.vbs” then you are on right post 🙂

Solution:

I tried doing this : regsvr32 %systemroot%\system32\vbscript.dll

http://www.technologystory.net/2009/02/25/windows-vista-tips-there-is-no-script-engine-for-file-extension-vbs/

But like you — for me too no luck 🙁

But finally following trick worked for me 🙂

1. Locate the file %windir%\inf\wsh.inf (inf is a hidden
folder)

2.right click and select “Install”.

Happy Coding!!

svn: Can’t create tunnel: The system cannot find the path specified.

We are using CruiseControl.NET for continuous integration. I must say really great tool!

We have configured a server where CruiseControl runs and our repository is on Tortoise SVN and it uses SVN+SSH. When we start our “ccnet.exe” it was giving us error like this “svn: Can’t create tunnel: The system cannot find the path specified.”

We really got confused as the message says the system can’t find the file specified But which file?? 🙁

After struggling a lot we found the solution..Here it is:

SVN_SSH Environment Variable value was like this[Won’t Work]:

C:\Program Files\Putty\bin\plink.exe

It should be like this [Will work]:

C:\\Program Files\\Putty\\bin\\plink.exe

OR

C:/Program Files/Putty/bin/plink.exe

That’s it!!

If you are new and don’t know how to access Environment Variables see this:http://www.pushok.com/help/svnscc/index.php?redirect=adv_svnssh.htm

HTH

"Writing a code is a one kind of prayer for me"

using Table control

Challenge:

How I generate <tbody> tag using Table, TableRow, etc … controls ?

I want to generate table o/p like this:

<table border="1">
  <thead>
    <tr>
      <th>Month</th>
      <th>Savings</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>$80</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>Sum</td>
      <td>$180</td>
    </tr>
  </tfoot>
</table>

Src : http://www.w3schools.com/TAGS/tag_tbody.asp

I want to create table like this from my code

behind using .net f/w classes.

Solution:

TableRow.TableSection is the solution for it:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.tablerow.tablesection.aspx

for whatever row you create just provide it’s TableSetion property to appropriate section e.g Body,head etc.

Hope this helps

Happy Programming!!

IE innerHTML – “Unknown runtime error”

Setting value of <div id=”divhtml”> using js like this :

document.getElementById(“divhtml”).innerHTML = “<form><input type=”text”>…</form>”;

it was giving me error..

Solution:

oldDiv = document.getElementById(divhtml);
newDiv = document.createElement(oldDiv.tagName);
newDiv.id = oldDiv.id;
newDiv.className = oldDiv.className;
newDiv.innerHTML = “<form><input type=”text”>…</form>”;

oldDiv.parentNode.replaceChild(newDiv, oldDiv);

And it worked like a charm!!!!!!

Link : http://piecesofrakesh.blogspot.com/2007/02/ies-unknown-runtime-error-when-using.html

There was an error while trying to serialize parameter http://tempuri.org/:obj. The InnerException message was ‘Type ‘System.Collections.Generic.List`1[Employee, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]’ with data contract name ‘ArrayOfEmployee:http://schemas.datacontract.org/2004/07/Interfaces’ is not expected. Add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

Hi if you are getting your hands dirty with WCF and got your mind blown up with the error as shown above or shown in Screen i have medicine of it..so go ahead!!!!

image

I am creating one simple serviceoperation which should take argument as an object but i will pass instance of my generic list which can be like List<Employee> or List<Person> and all this….because in service implementation i will do further operation based on type….I have created one application like this:

IService.cs

image

Service.CS

image

Employee.CS

image

Client.CS

image

Now when i run this application it gives me error of KnownTypeAttribute and serialization

Cause:

Actually root cause of problem is that we have defined object as our datacontract but when we pass List<Employee> or List<Person> it dosen’t knows what to serialize and send from wire…..hoohh…….simple if i have told you to say HI and it i will sat Bye…you can’t understand what i mean to say…so i need to help you in understanding Bye…Simple!!!!!so let us tell CLR that hey what to do if i pass List<Employee> or any type which i want to pass..

Solution:

Open your service contract IService.cs

and after [ServiceContract] Add [ServiceKnownType(typeof(List<Employee>))] or [ServiceKnownType(typeof(List<Person>))]….and Run the application…modified IService.cs looks like this:

image

Hope it helped you…Wants to say..Thanks say it to

Sowmy Srinivasan’s for nice and in-depth article:http://blogs.msdn.com/sowmy/

Question:

I am just wondering suppose if i have 50 Types which i want to pass then i need to declare all this on top of IService….just searching some alternative for it..if i found will let you know and hoping for the same….

EXECUTE permission denied on object ‘ABC’, database ‘XYZ’, schema ‘dbo’.

Error:

EXECUTE permission denied on object ‘usp_GetEmployeeDetails’, database ‘Employee’, schema ‘dbo’.

Solution:

  1. Expand your database Node. For me it’s “Employee”.
  2. Underneath of it Expand “Security” Node.
  3. Click on the user which you are using for Database operations. By default it is

MACHINENAME\ASPNET [MYMACHINE\ASPNET].

  1. It will open the window as shown below from database Roles Select db_owner:

clip_image002

That’s it…

“The underlying connection was closed: The connection was closed unexpectedly.” While returning Data Table from WCF service.

Error:

“The underlying connection was closed: The connection was closed unexpectedly.”

StackTrace:

System.ServiceModel.CommunicationException was unhandled by user code

Message=”The underlying connection was closed: The connection was closed unexpectedly.”

Source=”mscorlib”

StackTrace:

Server stack trace:

at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)

at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)

at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)

at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)

at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)

at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)

at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)

at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)

at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:

at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

at System.Web.UI.Control.OnLoad(EventArgs e)

at System.Web.UI.Control.LoadRecursive()

at System.Web.UI.Control.LoadRecursive()

at System.Web.UI.Control.LoadRecursive()

at System.Web.UI.Control.LoadRecursive()

at System.Web.UI.Control.LoadRecursive()

at System.Web.UI.Control.LoadRecursive()

at System.Web.UI.Control.LoadRecursive()

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

InnerException: System.Net.WebException

Message=”The underlying connection was closed: The connection was closed unexpectedly.”

Source=”System”

StackTrace:

at System.Net.HttpWebRequest.GetResponse()

at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

InnerException:

Scenario:

I have one OperationContract defined in my service contract which was returning DatTable as its return Type So it was looking like this:

[OperationContract]

DatTable LoadEmployeeInformation(long employeeID);

And in implementation I am filling this data Table using Table Adapter and returning it.

But it was throwing me error which was really annoying i had spent 4-5 hours to figure out it…

Solution:

I have changed my operation Contract to return Dataset Instead of Data Table

[OperationContract]

DataSet LoadEmployeeInformation(long employeeID);

and it worked like a charm!!!! For me…and hope that it works for you also…then go ahead and try this change….

Root cause:

Sorry guys I don’t know the root cause of this error. But i read some forums from Microsoft and they says that don’t use Data Table as a return type because some problem occurs in deserializaing it at client side…hooh…but I think it is BUG of WCF!!

Webliography:

http://connect.microsoft.com/wcf/feedback/ViewFeedback.aspx?FeedbackID=286535

http://processmentor.com/community/blogs/scott_middleton/archive/2007/06/08/169.aspx

http://blogs.msdn.com/lifenglu/archive/2007/08/01/passing-datatable-across-web-wcf-services.aspx

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1828652&SiteID=1&mode=1

http://blogs.conchango.com/merrickchaffer/archive/2007/09/19/WCF-System.Net.WebException_3A00_-The-underlying-connection-was-closed_3A00_-The-connection-was-closed-unexpectedly.aspx

-Kiran

The DataSourceID of ‘gridID’ must be the ID of a control of type IDataSource. A control with ID ‘objectcontainerdatasourceID’ could not be found.

The DataSourceID of ‘gridID’ must be the ID of a control of type IDataSource. A control with ID ‘objectcontainerdatasourceID’ could not be found.

Scenario:

I have One grid which is binded with objectcontainerdatasource. But when i try to run a page it shows me error as shown above.. i can’t figure it out why it working like so…but my colleague had found its solution.. Actually i have kept Grid and Objectconatinerdatasource within a Master page and it is underneath of LetZonePart..which is main problem.. when you run a page then it will hide all other controls which will not going to show on page e.g. ObjectContainerdatasoruce: so my old code which is not working is here:

<asp:Content ID=”Content1″ ContentPlaceHolderID=”LeftZoneParts” runat=”Server”>
<asp:GridView ID=”Mygview” runat=”server” AutoGenerateColumns=”false” Width=”950px” DataSourceID=”Myobjcdatasrc” >
<Columns>
//My Cols
</Columns>
</asp:GridView>
<pp:ObjectContainerDataSource runat=”server” ID=”Myobjcdatasrc” DataObjectTypeName=”Employee” />
<asp:content>

Solution:

Just put your grid and all stuff in ContentPlaceHolder rather than LeftZonePart. That’s it..working one is here…

<asp:Content ID=”Content1″ ContentPlaceHolderID=”ContentPlaceHolder1″ runat=”Server”>
<asp:GridView ID=”Mygview” runat=”server” AutoGenerateColumns=”false” Width=”950px” DataSourceID=”Myobjcdatasrc” >
<Columns>
//My Cols
</Columns>
</asp:GridView>
<pp:ObjectContainerDataSource runat=”server” ID=”Myobjcdatasrc” DataObjectTypeName=”Employee” />
<asp:content>

Happy Coding!!!