|
Thank you for your response.
It looks like I am not doing a good job of explaining the problem - sorry.
In our app, we are dynamically generating from the database the candidates names via radio button controls.
For instance, there is a table called Positions.
This table defines what position a candidate is running for.
For example, President, vice president, treasurer, etc.
On this same table is a field called choiceType.
This fieldname represents what choice a voter is presented with.
In our case, the choice is S for single choice or Radio button choice.
If there are 5 people running for president, on the db, each candidate would have the position of President and choiceType of S or Radio button as shown simply below:
Position choiceType
President S
On the markup
Five candidate names would be listed and radio button besides each name so user can check his/her favorite candidate.
So, my issue is that because these are dynamically generated from the db, though it gives us the chance to list another candidate called the Write In Candidate for each position that needs it, the issue is that when a user clicks Write In Candidate, we would like to make a textbox appear which allows the voter to write the candidate of his or her choice.
I think the reason I am having problem with this is because the original coder used DataList to display the candidates information and I can't figure out how to manipulate the code to display a textbox control when a user clicks on the Write In Candidate radio button.
Hope this is clearer.
Thanks again.
modified 24-Apr-16 19:37pm.
|
|
|
|
|
<asp:RadioButtonList ID="MyRadioList" runat="server" AppendDataBoundItems="true">
<asp:ListItem Value="-" Text="Other" />
</asp:RadioButtonList>
<asp:TextBox ID="txtOther" runat="server" />
<script type="text/javascript">
var txtOther = $("#<%=txtOther.ClientID %>");
txtOther.hide();
$(document).ready(function () {
$("input[type='radio'][name='MyRadioList'][value='-']").click(function () {
txtOther.show();
});
$("input[type='radio'][name='MyRadioList'][value!='-']").click(function () {
txtOther.hide();
});
});
</script>
|
|
|
|
|
Is there a way to upload screenshot here?
That's the best way to explain what is going on.
First, the textbox is supposed to display only on the Presidential section.
Instead, it displays on ALL positions.
I don't know if this is happening because we used DataList to display the positions.
Second, I just keep getting the following error:
Quote: Compiler Error Message: BC30451: 'writeIn' is not declared. It may be inaccessible due to its protection level.
and is pointing to this line:
var txtWriteIn = $("#<%=writeIn.ClientID %>");
Here is the code I am using after integrating your code:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AppendDataBoundItems="true" align="center" style="width:20px;height:20px;zoom:120%; white-space:nowrap;">
</asp:RadioButtonList></div>
<asp:TextBox ID="writeIn" runat="server"></asp:TextBox>
<script type="text/javascript">
var txtWriteIn = $("#<%=writeIn.ClientID %>");
txtWriteIn.hide();
$(document).ready(function () {
$("input[type='radio'][name='RadioButtonList1'][value='27']").click(function () {
txtWriteIn.show();
});
$("input[type='radio'][name='RadioButtonList1'][value!='27']").click(function () {
txtWriteIn.hide();
});
});
</script>
Thanks again for your help.
|
|
|
|
|
You shouldn't be getting that error, check the designer.cs file for the aspx page and see how writeIn is defined, it should be "protected". If it's not try amending it directly in the cs file, or deleting the control then re-adding it.
|
|
|
|
|
I don't have designer.cs because I am using website not web application.
It is wither .aspx or .aspx.vb and I don't have writeIn defined anywhere on codebehind.
This error is on markup specifically, the on the js file.
|
|
|
|
|
Not sure how you'd do this with a website I'm afraid, websites are seriously old technology you shouldn't be using.
|
|
|
|
|
samflex wrote: we used DataList to display the positions
So writeIn is defined within the ItemTemplate of a DataList ?
In that case, there won't be a field in the code-behind to represent it, because there could be any number of instances of the control.
Your name='RadioButtonList1' also won't work, as there will be multiple instances of that control as well, and each one will have a different name.
Use the Visible property on the TextBox to hide it on irrelevant sections:
<TextBox ID="writeIn" runat="server"
Visible='<%# ShowWiteInOnSection(Eval("SectionID")) %>'
/>
Move the script outside of the list, and change it to something like:
$(document).ready(function () {
$("input:radio[name$='RadioButtonList1']").click(function(){
$(this).closest("table").parent().find("input[name$='writeIn']").toggle(this.value === '27');
});
});
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
Sorry I don't know what this below means:
visible='<%# ShowWiteInOnSection(Eval("SectionID")) %>'/>
As always, thanks much for your help sir.
|
|
|
|
|
It's a data-binding expression to set the Visible property of the TextBox depending on which section it's in. Replace the ShowWiteInOnSection(Eval("SectionID")) part with whatever code you need to determine whether the current item is the "presidential" section.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry Richard, I spent so much time thinking about this and I am still confused as to what to do with
ShowWiteInOnSection .
For instance, I used this:
Protected Function GetMessageType(ByVal obj As Object) As String
Dim retVal As String = String.Empty
If obj IsNot Nothing AndAlso Not String.IsNullOrEmpty(obj.ToString()) Then
If obj.ToString() = "Charity - May 19 2016 " Then
retVal = "(Choose three members only)"
ElseIf obj.ToString() = "Board Election - Jun 5 2016 " Then
retVal = "(Choose only one candidate)"
ElseIf obj.ToString() = "Grievance Committee - May 12 2016 " Then
retVal = "(Choose two members only)"
End If
End If
Return retVal
End Function
to display what time of election is going on.
I know you said is a data binding to set visibility property of the Textbox depending on which section it is on but what I would like to accomplish if at all possible are two fold.
One, reflect the textbox only the section that has write In associated with the position and two, to display it only when the write in radio button is clicked.
And PositionID is what defines what position a candidate is competing for.
For instance, President is PositionID of 1; VP, 2; secretary 3; treasurer 4, etc.
These positions are on table called Positions
And then there is another table called Candidates that has candidateID, CandidateName, PositionId as FK to PositionID in Positions table.
So, this is where their names and their positions are joined.
I am stumped on how to code this function
ShowWiteInOnSection
|
|
|
|
|
So you only want to display the write-in textbox when PositionID is 1?
<TextBox ID="writeIn" runat="server"
Visible='<%# CInt(Eval("PositionID")) = 1 %>'
/>
Or:
<TextBox ID="writeIn" runat="server"
Visible='<%# ShowWiteInOnSection(Eval("PositionID")) %>'
/>
Protected Function ShowWiteInOnSection(ByVal PositionID As Object) As Boolean
Return CInt(PositionID) = 1
End Function
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you very much for your patience sir.
There are two issues here.
1, the textbox shows up on every position.
In other words, if I have the textbox like this:
<asp:textbox id="writeIn" runat="server" visible="true">, we would like to see that it is only on the President section.
However, we want it hidden but when we click on the radio button, we will like it to be displayed so users can enter their candidate of choice.
I wanted to add that right now, it shows the Write In textbox only in President section which is awesome but we would like that to show only after the Write In Candidate box is checked.
Again, many thanks for your help and patience Richard.
modified 28-Apr-16 16:12pm.
|
|
|
|
|
Try adding style="display:none;" to the textbox:
<TextBox ID="writeIn" runat="server"
Visible='<%# CInt(Eval("PositionID")) = 1 %>'
style="display:none;"
/>
The Javascript will then show the textbox when you select the "write-in" option:
$(document).ready(function () {
$("input:radio[name$='RadioButtonList1']").click(function(){
$(this).closest("table").parent().find("input[name$='writeIn']").toggle(this.value === '27');
});
});
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you so so much.
Hopefully, this is the last question.
It doesn't matter what I try, I click the write in radio button but the box doesn't get displayed.
The is the markup:
<tr>
<td style="text-align: right;">
<asp:RadioButtonList ID="RadioButtonList1" class="radio4" runat="server" style="width:20px;height:20px;zoom:120%; white-space:nowrap;" TextAlign="Left">
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" Runat="server"
ControlToValidate="RadioButtonList1" ForeColor="Red" Display="Dynamic" ErrorMessage="Required"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="writeIn" style="display:none;" runat="server" visible='<%# ShowWriteInOnSection(Eval("PositionId")) %>'/>
</td>
</tr
and this is the html when I right-click to View Source:
<tr>
<td style="text-align: right;">
<table id="DataList1_RadioButtonList1_1" class="radio4" style="width:20px;height:20px;zoom:120%; white-space:nowrap;">
<tr>
<td><label for="DataList1_RadioButtonList1_1_0_1">Johnny Walker</label><input id="DataList1_RadioButtonList1_1_0_1" type="radio" name="DataList1$ctl02$RadioButtonList1" value="34" /></td>
</tr><tr>
<td><label for="DataList1_RadioButtonList1_1_1_1">Write In Candidate</label><input id="DataList1_RadioButtonList1_1_1_1" type="radio" name="DataList1$ctl02$RadioButtonList1" value="35" /></td>
</tr>
</table>
<span id="DataList1_RequiredFieldValidator2_1" style="color:Red;display:none;">Required</span>
</td>
</tr>
<tr>
<td>
<input name="DataList1$ctl02$writeIn" type="text" id="DataList1_writeIn_1" style="display:none;" />
</td>
</tr
|
|
|
|
|
Looks like the Javascript can't find the textbox. Also the "write-in" value doesn't match what you previously told us.
Try something like this:
$(document).ready(function () {
$("input:radio[name$='RadioButtonList1']").click(function(){
var name = this.name;
name = name.substr(0, 1 + name.lastIndexOf("$")) + "writeIn";
$("input[name='" + name + "']").toggle(this.value === "35");
});
});
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You are such an awesome, brilliant guy.
Works like a dream.
Thanks so much for your kindness
modified 2-May-16 9:42am.
|
|
|
|
|
Hi,
I have reffered sample project given on below link.
http://www.codeproject.com/Articles/18952/Using-SOAP-Extensions-to-provide-progress-notification
But I am stuck at configuration for applying this extension to specific method inside my wcf service.Any help will be appreciated.
|
|
|
|
|
If you have a question about an article, use the forum at the bottom of the article. The author of the code is the person most likely to be able to help you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hello...pls help me im beginner in mvc ...working in MVC4..
binding dropdown like Country,State,City..when im selecting any one country it showing me all country's state and city..
i want to show country's related State..and that state's related all City..pls help..what i want to do..
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcDdlStudCRUD.Models;
namespace MvcDdlStudCRUD.Controllers
{
public class HomeController : Controller
{
private WorkTraningEntities db = new WorkTraningEntities();
//
// GET: /Home/
public ActionResult Index()
{
var students = db.Students.Include(s => s.City).Include(s => s.Country).Include(s => s.State);
return View(students.ToList());
}
//
// GET: /Home/Details/5
public ActionResult Details(int id = 0)
{
Student student = db.Students.Find(id);
if (student == null)
{
return HttpNotFound();
}
return View(student);
}
//
// GET: /Home/Create
public ActionResult Create()
{
ViewBag.CityID = new SelectList(db.Cities, "CityID", "CityName");
ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName");
ViewBag.StateID = new SelectList(db.States, "StateID", "StateName");
return View();
}
//
// POST: /Home/Create
[HttpPost]
public ActionResult Create(Student student)
{
if (ModelState.IsValid)
{
db.Students.Add(student);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.CityID = new SelectList(db.Cities, "CityID", "CityName", student.CityID);
ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", student.CountryID);
ViewBag.StateID = new SelectList(db.States, "StateID", "StateName", student.StateID);
return View(student);
}
public JsonResult SelectStates(int id)
{
IEnumerable<State> states = db.States.Where(stat => stat.CountryID == id);
return Json(states);
}
//
// GET: /Home/Edit/5
public ActionResult Edit(int id = 0)
{
Student student = db.Students.Find(id);
if (student == null)
{
return HttpNotFound();
}
ViewBag.CityID = new SelectList(db.Cities, "CityID", "CityName", student.CityID);
ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", student.CountryID);
ViewBag.StateID = new SelectList(db.States, "StateID", "StateName", student.StateID);
return View(student);
}
//
// POST: /Home/Edit/5
[HttpPost]
public ActionResult Edit(Student student)
{
if (ModelState.IsValid)
{
db.Entry(student).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.CityID = new SelectList(db.Cities, "CityID", "CityName", student.CityID);
ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", student.CountryID);
ViewBag.StateID = new SelectList(db.States, "StateID", "StateName", student.StateID);
return View(student);
}
//
// GET: /Home/Delete/5
public ActionResult Delete(int id = 0)
{
Student student = db.Students.Find(id);
if (student == null)
{
return HttpNotFound();
}
return View(student);
}
//
// POST: /Home/Delete/5
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
Student student = db.Students.Find(id);
db.Students.Remove(student);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
‹ Previous Thread|Next Thread ›
Microsoft Ad
|
|
|
|
|
What you need to do is create jquery change event on the country ddl and pass the country Id to controller and update the states ddl with the results filtered by the country id selected.
Do the same for state and cities too.
I can see some code for states SelectStates() but don't know where you have used it.
|
|
|
|
|
This is for my new program written in MVC, in which I'm using lots avatars to represent things like users and items.
In my old program code in VB, I picked up the image from the disk drive, make a new canvas and wrote the image on the new canvas centering it back to the drive.
In this program, I got slick and took the bytes[] from file upload, and then I feed them into this function that returns the image back to me in various formats such as bytes[]. The program works, but I just can't get the new resized image to center on the canvas, it always starts on the left edge. The height is correct, but I get a black strip on the right side because it's smaller.
I'm not looking for someone to write code for me, just take a look at the function and perhaps you can see where I blew it and made a mistake. Perhaps its the order of graphic objects, maybe I have it backwards.
<pre lang="text"> Your codeblocks should be of the form
```C#
public static model_image_object avatar_resize(string pName, byte[] pBytes)
{
const int t_Width = 250;
const int t_Height = 250;
int cHeight = 0;
int cWidth = 0;
model_image_object pResult = new model_image_object();
MemoryStream stream_out = new MemoryStream();
using (Stream stream_in = new MemoryStream(pBytes))
{
Image image_in = Image.FromStream(stream_in);
int oWidth = image_in.Width;
int oHeight = image_in.Height;
Color bgColor = Color.FromArgb(255, 255, 255);
using (Bitmap bitmapObj = new Bitmap(t_Width, t_Height, PixelFormat.Format24bppRgb))
{
using (Graphics graphicObj = Graphics.FromImage(bitmapObj))
{
graphicObj.Clear(Color.Transparent);
graphicObj.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
graphicObj.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
if (oWidth == oHeight)
{
cWidth = 250;
cHeight = 250;
}
else if (oWidth > t_Width)
{
cWidth = t_Width;
cHeight = (int)Math.Round((oHeight / (float)oWidth) * t_Width);
}
else if (oWidth < t_Width)
{
cWidth = (int)Math.Round((oWidth / (float)oHeight) * t_Height);
cHeight = (int)Math.Round((oHeight / (float)oWidth) * cWidth);
}
else if (oHeight > t_Height)
{
cHeight = t_Height;
cWidth = (int)Math.Round((oWidth / (float)oHeight) * t_Height);
}
int x = (cWidth - t_Width) / 2;
int y = (cHeight - t_Height) / 2;
graphicObj.DrawImage(image_in, x, y, t_Width, t_Height);
graphicObj.Save();
}
bitmapObj.Save(stream_out, ImageFormat.Png);
}
}
pResult.Data = stream_out.ToArray();
pResult.Name = pName;
pResult.Type = "image/png";
pResult.Size = new model_image_type_size();
pResult.Size.Height = cHeight;
pResult.Size.Width = cWidth;
return pResult;
}
```
public class model_image_object
{
public string Name { get; set; }
public string Type { get; set; }
public byte[] Data { get; set; }
public model_image_type_size Size { get; set; }
}
|
|
|
|
|
How about something like this:
if (oWidth <= t_Width && oHeight <= t_Height)
{
cWidth = oWidth;
cHeight = oHeight;
}
else if (oHeight < oWidth)
{
cWidth = t_Width;
cHeight = (int)Math.Round((oHeight / (float)oWidth) * t_Width);
}
else
{
cHeight = t_Height;
cWidth = (int)Math.Round((oWidth / (float)oHeight) * t_Height);
}
int x = (t_Width - cWidth) / 2;
int y = (t_Height - cHeight) / 2;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well I've been working on this all morning. And your right, it was my calculation and I did get the Graphics and Bitmap objects right.
So after hours of using my calculator and confirming formulas, I had nothing. Then I decided to search for the same formula but written better and came across this. I looked at it and deemed it to be highly optimized already.
Well at least I got the thought right about canvas, ratios, positions, for the code just slid right into my code.
Thanks Richard, it was head scratcher. But I went with this instead.
On the positive side, I must admit that this function is pretty slick now that it works correctly.
Working with images as byte arrays is pretty cool for storing them in the database and writing them as files for HTTP calls.
On the negative side, working with numbers in c# is much different that VB. C# doesn't divide integers, didn't know that.
graphicObj.Clear(Color.Transparent);
graphicObj.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
graphicObj.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
double ratioX = (double)canvasWidth / (double)originalWidth;
double ratioY = (double)canvasHeight / (double)originalHeight;
double ratio = ratioX < ratioY ? ratioX : ratioY;
int newHeight = Convert.ToInt32(originalHeight * ratio);
int newWidth = Convert.ToInt32(originalWidth * ratio);
int posX = Convert.ToInt32((canvasWidth - (originalWidth * ratio)) / 2);
int posY = Convert.ToInt32((canvasHeight - (originalHeight * ratio)) / 2);
graphicObj.Clear(Color.White);
graphicObj.DrawImage(image_in, posX, posY, newWidth, newHeight);
graphicObj.Save();
credit goes to
User egrunin - Stack Overflow[^]
|
|
|
|
|
when im trying this code in MVC4 Getting an error..
The name 'ObjectFactory' does not exist in the current context
using eManager.Domain;
using eManager.Web.Infrastructure;
using StructureMap;
namespace eManager.Web {
public static class IoC {
public static IContainer Initialize() {
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
x.For<idepartmentdatasource>().HttpContextScoped().Use<departmentdb>();
});
return ObjectFactory.Container;
}
}
|
|
|
|
|
Just going out on a limb here, but I think you may have a "public class ObjectFactory" instead of a "public static class ObjectFactory".
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|