hi all,
In my web page i have created radio buttons dynamically on to the page .....following is my code -
string Course, Semester, Section;
-
int rowsCount;
-
string con = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
-
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
try
-
{
-
SqlConnection objCon;
-
SqlDataAdapter objDA;
-
Course = (string)Session["Course"];
-
Semester = (string)Session["Semester"];
-
Section = (string)Session["Section"];
-
if (!IsPostBack)
-
{
-
string strFeedBackDetails = "";
-
Response.Write("<i>COURSE</i> <b> :" + Course + " </b> | ");
-
Response.Write("<i>SEMESTER</i> <b> :" + Semester + "</b> | ");
-
Response.Write("<i>SECTION </i><b> :" + Section + "</b><br/><br/><br/><br/>");
-
string query = "select SubjectCode from tblCollegeSubject where CourseName = '" + Course + "' and Semester = '" + Semester + "' union select miscSubject from tblCollegeMisc";
-
objCon = new SqlConnection(con);
-
objDA = new SqlDataAdapter(query, objCon);
-
DataTable objDT = new DataTable("tblSubjectCode");
-
objDA.Fill(objDT);
-
rowsCount = objDT.Rows.Count;
-
strFeedBackDetails += "<div align=\"center\"><table align=\"center\" cellpadding=\"5\" cellspacing=\"2\" frame=\"border\" bordercolordark=\"#000000\">" +
-
"<tr bgcolor=Gray><th><b>SUBJECT</b></th>" +
-
"<th><b>EXCELLENT-1</b></th><th><b>VERY GOOD-2</b></th>" +
-
"<th><b>GOOD-3</b></th><th><b>AVERAGE-4</b></th>" +
-
"<th><b>POOR-5</b></th><th><b>COMMENTS</b></th></tr>";
-
-
for (int count = 0; count < rowsCount; count++)
-
{
-
strFeedBackDetails += "<tr><td style=\"font-style: italic;\"><input type=text name=\"subject\" readonly=\"readonly\" id=\"txtSubject" + count.ToString() + "\" value='" + objDT.Rows[count]["SubjectCode"].ToString() + "' style=\"display: block; visibility: visible;\"></td>";
-
strFeedBackDetails += "<td><input type=radio id='rbgrade1" + count.ToString() + "' value=\"A\" name='grade" + count.ToString() + "' /></td>";
-
strFeedBackDetails += "<td><input type=radio id='rbgrade2" + count.ToString() + "' value=\"B\" name='grade" + count.ToString() + "' /></td>";
-
strFeedBackDetails += "<td><input type=radio id='rbgrade3" + count.ToString() + "' value=\"C\" name='grade" + count.ToString() + "' /></td>";
-
strFeedBackDetails += "<td><input type=radio id='rbgrade4" + count.ToString() + "' value=\"D\" name='grade" + count.ToString() + "' /></td>";
-
strFeedBackDetails += "<td><input type=radio id='rbgrade5" + count.ToString() + "' value=\"E\" name='grade" + count.ToString() + "' /></td>";
-
strFeedBackDetails += "<td><input type=text id='txtComments" + count.ToString() + "' name=\"txtComments\" maxlength=200 /> </td>";
-
strFeedBackDetails += "</tr>";
-
}
-
strFeedBackDetails += "<tr><td colspan=7 align=center><input type=\"submit\" id=\"btnSave\" value=\"Save\" language=\"javascript\" onClick=\"return Save()\" /></td>";
-
strFeedBackDetails += "<td><input type=hidden id=\"hidCount\" name=\"hidCount\" value='" + objDT.Rows.Count.ToString() + "'/></td></tr>";
-
strFeedBackDetails += "</table></div>";
-
Page.Form.Controls.Add(new LiteralControl(strFeedBackDetails));
-
}
-
else
-
{
-
string lstrSubject = null;
-
string lstrComments = null;
-
string[] larrSubject = null;
-
string[] larrComments = null;
-
int lrowsCount = Convert.ToInt16(Request["hidCount"]);
-
lstrSubject += (Request["subject"]);
-
lstrComments += (Request["txtComments"]);
-
larrSubject = lstrSubject.Split(',');
-
//showControlids();
-
larrComments = lstrComments.Split(',');
-
string[] lgrade = new string[lrowsCount];
-
objCon = new SqlConnection(con);
-
SqlCommand objCmd = new SqlCommand("uspInsFeedBack", objCon);
-
objCmd.CommandType = CommandType.StoredProcedure;
-
objCmd.Parameters.Add("@FeedBackDate", SqlDbType.DateTime).Value = System.DateTime.Now.ToString();
-
objCmd.Parameters.Add("@CourseName", SqlDbType.Char).Value = Course;
-
objCmd.Parameters.Add("@Semester", SqlDbType.Char).Value = Semester;
-
objCmd.Parameters.Add("@SectionName", SqlDbType.Char).Value = Section;
-
SqlParameter RetVal = objCmd.Parameters.Add("@Refer", SqlDbType.Int);
-
RetVal.Direction = ParameterDirection.Output;
-
try
-
{
-
objCon.Open();
-
objCmd.ExecuteNonQuery();
-
for (int count = 0; count < lrowsCount; count++)
-
{
-
lgrade[count] = (Request["grade" + count.ToString()]);
-
string insertSQL;
-
insertSQL = "INSERT INTO tblCollegeFeedBackForm(";
-
insertSQL += "SubjectCode, FeedBackId, Grade, Comments)";
-
insertSQL += "VALUES (";
-
insertSQL += "@SubjectCode, @FeedBackId, @Grade, @Comments )";
-
SqlCommand objCmd1 = new SqlCommand(insertSQL, objCon);
-
objCmd1.Parameters.Add(new SqlParameter("@SubjectCode", SqlDbType.Char));
-
objCmd1.Parameters["@SubjectCode"].Value = larrSubject[count];
-
objCmd1.Parameters.Add(new SqlParameter("@FeedBackId", SqlDbType.Int));
-
objCmd1.Parameters["@FeedBackId"].Value = RetVal.Value;
-
objCmd1.Parameters.Add(new SqlParameter("@Grade", SqlDbType.Char));
-
objCmd1.Parameters["@Grade"].Value = lgrade[count];
-
objCmd1.Parameters.Add(new SqlParameter("@Comments", SqlDbType.VarChar, 200));
-
objCmd1.Parameters["@Comments"].Value = larrComments[count];
-
objCmd1.ExecuteNonQuery();
-
}
-
}
-
catch (SqlException er)
-
{
-
Response.Write(er.Message);
-
}
-
finally
-
{
-
objCon.Close();
-
}
-
}
-
}
-
catch (Exception er)
-
{
-
Response.Write(er.Message);
-
}
-
}
-
And now i want to validate the page before it get submited...i want the user to check radio buttons in each row.. i validated using javascript as follows -
<script language="javascript" type="text/javascript">
-
<!--
-
-
function Save()
-
{
-
var countId=getElementByName('hidCount');
-
var Count=countId.value;
-
var check='check';
-
for(i=0;i<count;i++)
-
{
-
var grade[i]=getElementByName('grade'+i);
-
for(j=0;j<grade[j].length;i++)
-
{
-
if(grade[j].checked==true)
-
{
-
check=grade[i].value();
-
}
-
}
-
if(check=='check')
-
{
-
alert('PLZ Grade The Subject');
-
return false;
-
}
-
else
-
return true;
-
}
-
}
-
i cold not able to validate becoz i could not get the the value of hidden variable and radio button....can any one plz solve by problem...
thanks
5 6677
The first thing I'm going to say is that Response.Write should not be used in your C# code.
Why would I say such a thing?
Glad you asked, it writes the content "somewhere" in the output content stream.
What on earth does that mean?
Well it means that when you use Response.Write(), the string is written anywhere in the content stream sent to the browser. This usually results in the content being placed somewhere before the <html> tag, or somewhere between the <head> and <body> tags....
If you don't believe me, run your application, right click on it and click "view code"...
Do you see it?
Your HTML isn't valid is it?
Response.Write should only be called from the asp code.
Not used in the C# code.
This is probably why you're having problems.
I strongly recommend you use ASP.NET controls since you are developing an ASP.NET application.
In your case, I would recommend looking up the RadioButtonList Control, Repeaters .....and Labels
Hi satyabhaskar,
frinvale sir is right you can use response.write. -
Page.Form.Controls.Add(new LiteralControl(strFeedBackDetails));
insted this code you can write this way - Response.Write(strFeedBackDetails);
but if you want to check validation you have to make function in javascript;
whenever you find control in javascript you use this line - document.getElementByName
-
//(or)
-
document.getElemenetById
@Frinavale
hi boss...
yes boss ur right.... im sorry the title which i displayed is wrong. actually i did not used response.write... i find the same fault which u said and i changed my code accordingly.... i used - Page.Form.Controls.Add(new LiteralControl(strFeedBackDetails));
and nw my problem is i couldnt get the control's id when iam validating them client side using java script.........i don't need to validate all the controls its enough if i can validate radio buttons in each row....
hey boss i got the solution.... just want to share..... my code is as follows... -
<script language="javascript" type="text/javascript">
-
function valid(e)
-
{
-
for(var i=0;i<e.length;i++)
-
{
-
if(e[i].type=='radio')
-
{
-
var r=e[e[i].name], check=true;
-
for(var j=0;j<r.length;j++)
-
{
-
if(r[j].checked)
-
check=false;
-
}
-
if(check)
-
{
-
alert('Please Grade All The Subjects');
-
return false;
-
}
-
else
-
return true;
-
}
-
}
-
}
-
</script>
-
</head>
-
<body>
-
<form id="form1" method="post" name="form1" runat="server" onsubmit="return valid(this.elements)" >
-
</form>
-
</body>
-
</html>
-
I'm glad you found your solution :)
For your information, the reason why you couldn't get the control's ID for validation using JavaScript is because Literal Controls just print pure text. This text does not have an ID associated with it...
If you had used a Label, your text would have been rendered in <span> tags, which has an ID that will let you access it with JavaScript.
In your case, you want to validate a RadioButtonList, which has an ID...
Your solution works fine for your purposes though: loop through all of the elements in the page and find a Radio Button List....then validate.
For more information check out how to use JavaScript in ASP.NET Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian |
last post by:
Hello all...
I have a page that will be performing a search. The search consists of 3
radio button options. The first 2 will search the entire web through google
and the site as indexed by...
|
by: sman |
last post by:
Hi, I recently read this article on About.com on how to create
required fields for a form:
http://javascript.about.com/library/scripts/blformvalidate.htm
Everything works great except that there...
|
by: obsidian8 |
last post by:
Hi All,
I have looked around for an answer to this question, but haven't found
one as of yet. I'm trying to use javascript to dynamically create
raido buttons. I am able to create them easily...
|
by: Ken Varn |
last post by:
This is probably a simple question, but I am new to this so bear with me.
I have a ASP.NET form that has a checkbox and a 2 radio buttons. When the
checkbox is checked, the 2 radio buttons are...
|
by: Karthick Kumar |
last post by:
Hi,
I have the following code which displays all the images from a
specific folder with a Radio button in it:
Dim objFile
i = 1
For Each objFile In objFolder.Files
If (i = 1) Then...
|
by: James P. |
last post by:
Help,
I need to display radio buttons on a form. The data is from SQL
table: each row in each table is displayed as a radio button. I have
multiple SQL tables so I understand I need to put...
|
by: Blinky |
last post by:
Hi all,
I have a dynamically generated page that can have 1 or more radio buttons. I
am using javascript with onsubmit in the form statement to make sure a radio
button is selected before...
|
by: moksha |
last post by:
Hi,
I am new to javascript and i am facing a problem in coding.
plz help me out.
I am using javascript for dynamically creating a table row which contains text boxes and radio...
|
by: swapnil1987 |
last post by:
hello friends i am trying to find solution for this problem if u know something then please tell
i am creating web application that runs on black berry.
here i need to create selection list...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |