How do I develop an online survey application? - asp.net

I want to develop application that contain number of question with independent radiobuttonlist which contain three option Yes, No, Unsure.
Daily visitors comes on the site & reply to the question. Also to show addition of the Yes, NO & Unsure in front of each question.
Please give me idea how to do such functionalty.
Regards,
Girish

Quickest and easiest way would be to piggy-back on an existing site.
http://www.polldaddy.com/ will allow you to embed polls in your own site

This is a very vague question and probably won't get much of an answer.
What technology do you want to use, .Net, Java. PHP etc, what resources do you have available?
Essentially you need some sort of database to store the questions and answers in and a front end web application built in whatever technology you decide on (as stated .net, Java or PHP are probably the most common).

Create a custom control that uses an Update Panel. Inside the update Panel you will have two PlaceHolders - 1 for your questions and 1 for your results. Hide the results placeholder by default. Once the radiobutton (OnSelectedIndexChanged) is selected, cause a postback and calculate the results. In the same Postback method, hide the Question placeholder and show the results placeholder with the calculated results.
Your page could look like this:
<UpdatePanel ID="upPanel" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="plcQuestion" runat="server">
Have you ever written asp.net code?
<asp:RadioButtonList ID="radList" AutoPostBack="true" OnSelectedIndexChanged="doStuff">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>Unsure</asp:ListItem>
</asp:RadioButtonList>
</asp:PLaceholder>
<asp:PlaceHolder ID="plcAnswers" runat="server" Visible="false">
Results:
Yes: <asp:Label ID="lblYesResults" runat="server" />
No: <asp:Label ID="lblNoResults" runat="server" />
Unsure: <asp:Label ID="lblUnsureResults" runat="server" />
</asp:PLaceholder>
</ContentTemplate>
</UpdatePanel>
Then, on your "doStuff" method, just save the results and populate whatever result display you are going for. Hope this helps!

Related

Pass variable used in aspx page to user control

We are in ASP.Net Webforms. I come from a LAMP Stack mindset...
ASPX Code (part of it)
<asp:Content runat="server" ContentPlaceHolderID="PH_MainContent">
<h3 class="fleft">
<asp:Literal runat="server" ID="li_title" />
...
<Example:userControl runat="server" someVariable="text" otherVariable=<%=li_title.Text%> thirdVariable=<%=Items["sort"].toString()%> />
So, li_title is a literal set in the code behind, I want to reuse it later, passing it to a userControl, where it shall be displayed in a javascript. Items is page.Items. I have also tried this.li_title (which is suggested to me in Visual Studio 2015).
After reading "quite a few" very similar questions, this seem the solution. However obviously I'm missing the point. What would that be..?
You can create a public property for each variable on your user control and set them in aspx. See this for more information

URL rewriting in ASP.NET 4.0 on radiobutton check event

I am trying to change URL of website and need help for the same. The scenario is that I have a search engine for student search and have different criteria for refine search. By default I am showing all the student data on homepage and when we use search the result is displayed on the same page, so URL of the page does not change.
My search criteria are by date of join(1 month,2months,6months,1Yr) and state they belong from. I have added radio button for refine search, so on "OnCheckedChanged" event the data gets populated on the page. So now how do I change the URL so as to show something like, say I have website www.xyz.com and need to show www.xyz.com/bydate/1month or www.xyz.com/bystate/LA. Have googled many links but not able to understand how to start.
Below is snippet of my code
<asp:DataList ID="dlJoin" CssClass="slider" r RepeatColumns="1" RepeatDirection="Vertical" runat="server" OnItemDataBound="dlJoin_ItemDataBound">
<ItemTemplate>
<label style="text-align: left; margin-left:15px;">
<asp:RadioButton ID="rddlJoin" CssClass="radiobooking" Checked="false" AutoPostBack="true" OnCheckedChanged="rddlJoin_checkchanged" GroupName="rdGroupTag" runat="server" onKeyPress="return suppress(event);" /><%#Eval("Name")%>
</label>
<asp:Literal runat="server" Visible="false" ID="litdlJoin" Text='<%#Eval("Value")%>'></asp:Literal>
</ItemTemplate>
</asp:DataList>
I would do this with Javascript and not worry about redirecting on the server side(assuming that all your clients should have javascript). You can do a "pure" redirect by using something like
window.location.href = "http://xyz.com/bydate/1month";
This has equivalent behavior as to if you clicked on a link to that URL.
If you're wanting to use Ajax and make things be a bit nicer looking(and no full page loads) you can use a combination of # URL changes and using a tool like jQuery to easily load a div or some such from another URL

Create a web page as 2 parts

I want to develop a registration form with 2 panels. One panel is personal information and another is address details. In these panels the user fills in all details of personal information and after completion of this, the user clicks on Add Address Details. If the user clicks on that, the second panel should be visible without page refresh. How can I accomplish this?
you would use javascript to append the append the second form to to the div of the first form. Or however you have it setup. So in jquery it would look something like this:
<script type="text/javascript">
$('#buttonid').click(function() {
$('#divid').append("<form><input />etc etc etc</form>");
});
</script>
You should use the ASP.NET Wizard control. It is the perfect tool for these scenarios. Scott Gu has a post with some links explaining how to use it. I recommend you look at it.There's a video linked that walks you through a full example.
I don't know, but hiding/showing panels based on certain conditions on the same page feels inelegant and hacky to me.
You should look into using an UpdatePanel. Within there you could place to Panels with different form information. Tie in a few button clicks and hide/show the different panels.
Edit with a simple example
<asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
<asp:UpdatePanel id="upnl" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Panel ID="pnl1" runat="server">
<!--personal info-->
<asp:Button ID="btn1" runat="server" Text="this button could validate personal info, hide pnl1 and show pnl2" />
</asp:Panel>
<asp:Panel ID="pn2" runat="server" Visible="false">
<!--address info-->
<asp:Button id="btn2" runat="server" Text="this button could validate address information and finally submit the form." />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>

ASP.NET 2 Control Properties Databinding does not always work

I've got the beautiful task at hand to look at some nice legacy asp.net 2 code and implement some new controls.
It's my first attempt at asp.net (the classic one, i've experimented with mvc a bit) so i am not too fond of it.
Right now i am trying to understand why a databinding sometimes works and a similar binding wont work on another page.
<asp:ImageButton ID="SaveAsPDFButton" runat="server"
ImageUrl='<%#GetPdfIconSmallPath() %>'
ToolTip='<%$ Resources:SaveAsPDFButton.Text %>'
CausesValidation="false" />
While the Tooltip gets evaluated and set, the ImageUrl of this control wont be set. The function is not getting executed. I've tried all, even disabling ViewState on it.
On other places, this same code however works just fine, like this small snippet here which does exactly what you might expect it to do:
<asp:HyperLink ID="InvHl" runat="server">
<asp:Image ID="Img1" ImageUrl='<%#GetPdfIconSmallPath() %>' runat="server" />
</asp:HyperLink>
Same thing occurs with the Visible Property of an ASP:Panel i have on other places in this page.
Any ideas on how to get this working appreciated!
We didnt really solve the problem but switched to the newest version of ASP.NET which does not show such a strange behaviour.

ASP.Net - Two way databinding of a single entity - Options, best way...roll your own?

I have been searching around to find the best option of doing this.
Basically, I want to do two way databinding of multiple controls (textbox, dropdownlist, checkbox, etc) to a single instance of custom class/entity, ie: Person.
It seems, the (only?) way to do this is using an like so:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="OrderID"
DataSourceID="SqlDataSource1" DefaultMode="Edit">
<EditItemTemplate>
OrderID:
<asp:Label ID="OrderIDLabel1" runat="server" Text='<%# Eval("OrderID") %>' />
<br />
CustomerID:
<asp:DropDownList ID="CustomerIDDropDownList" runat="server"
DataValueField='CustomerID' DataSourceID="CustomerDataSource"
DataTextField="CompanyName"
SelectedValue='<%# Bind("CustomerID") %>'
/>
EmployeeID:
<asp:TextBox ID="EmployeeIDTextBox" runat="server"
Text='<%# Bind("EmployeeID") %>' />
<br />
Some issues:
- This is limited to using an ObjectDataSource control (ie: can't just use an instance of the desired class in the code behind)
- Forces you to define a second (likely identical layout) read only template....would be nice to have some some mechanism that could intelligently render a read-only view derived from the edit template.
- The binding declaration Text='<%# Bind("EmployeeID") %>' is loosely typed, so vulnerable to spelling errors
- etc
So my first question I guess is, is an asp:FormView the only way in ASP.Net to do declarative databinding of a single entity?
Secondly, how feasible would it be to hand roll some sort of a two way binding mechanism? I guess it would have to be reflection based, but I could live with that. Anyone recommendations on how one would declare the binding relationships in the aspx page? Would the proper way be like:
Text='<%# MySuperDuperBind("EmployeeID") %>'
And then somewhere (where?) my MySuperDuperBind implementation will get called as the page is rendered....how this is done is a bit beyond me though. And if I want to render in readonly, I can call a secondary function that will remove the editable UI control from the form and replace it with the corresponding read only version (ie: a Textbox is replaced with a Label).
Another alternative route is getting away from webforms and going to a client side templating solution such as this very nice looking solution:
http://weblogs.asp.net/dwahlin/archive/2009/05/03/using-jquery-with-client-side-data-binding-templates.aspx
However, I have no clue how to write the asp.net webservices properly in order to retrieve and save data in this type of an architecture.
Ideas?
is an asp:FormView the only way in
ASP.Net to do declarative databinding
of a single entity?
There's also DetailsView but it has the same issues.
I've mostly given up on 2-way databinding. It's great for prototyping and gets me 80-90% of the way to a complete solution but the last 10-20% is a nightmare. Binding any non-trivial object always seems to involve so many event handlers to customize behavior that it feels like spaghetti code to me.
I usually have two methods:
MapEntityToView(entity)
MapViewToEntity(entity)
that I call to display the entity and to populate from the page, respectively. It can be tedious to write but I don't have to wrestle with data binding issues.
I do use 1-way binding extensively for read only pages and displaying items in list controls.

Resources