|
As I said in the above reply that you need to make sure you readd the dynamic controls on postback and the ASP.NET does not do that for you. Now go back to your sample code in the Page_Load event handler, you are checking the if(!IsPostBack) and adding the dynamic radios in the if statement body. That also means this code only executes just one time when the page is first visited, and when you hit the Next button to cause the postback, this code does not execute due to the code if(!IsPostBack) . As a result of that, the dynamic radios do not get reinserted to the web page, and you find no thing in the CheckAnswers. If you still don't get it, you can try stepping through your code in debog mode and see how the Page_Load executes. So the simple fix is that you don't check the IsPostback in the Page_Load.
|
|
|
|
|
I have already tried without if(!IsPostBack) and all the radios are there but none is checked. I guess that by recreating them I recreate their checked state too.
--Nikola--
modified 7-Dec-20 21:01pm.
|
|
|
|
|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) Normally, there are a couple of reasons that causes the ViewState of a control to get lost:
+ The control has the ViewState disabled.
+ The control is dynamically readded after the ViewState is loaded.
+ The control has different ID when the ViewState is loaded. For example, when the ViewState is saved the control'ID is "Radio1", but when the ViewState is loaded on postback the value of the ID is "Radio2".
Below is a working example:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder runat="server" ID="PlaceHolderControl1"></asp:PlaceHolder>
<br />
<asp:Button runat="server" ID="btnPushMe" Text="Pushed Me!" OnClick="btnPushMe_Click" />
</div>
</form>
</body>
</html>
//Code-behind
public partial class Default1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Table table = new Table();
for (int rowIndex = 0; rowIndex < 3; rowIndex++)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
RadioButton radio = new RadioButton();
radio.ID = "Radio_" + rowIndex.ToString();
radio.GroupName = "RadioGroup";
cell.Controls.Add(radio);
row.Cells.Add(cell);
table.Rows.Add(row);
}
PlaceHolderControl1.Controls.Add(table);
}
protected void btnPushMe_Click(object sender, EventArgs e)
{
for (int rowIndex = 0; rowIndex < 3; rowIndex++)
{
RadioButton radio = (RadioButton)PlaceHolderControl1.FindControl("Radio_" + rowIndex.ToString());
Response.Write(string.Format("Radio {0}'s checked state : {1} <br>", rowIndex, radio.Checked));
}
}
}
|
|
|
|
|
the numeric pages on my datagrid is not working properly if for example i am displaying pages 1 to 10 but there are 90 pages
there is an option to choose "..." which then displays the other pages numbers but when i try to choose one of these numbers for example page 13 it carry's me right back to page 3 instead of page 13
kenny
|
|
|
|
|
Could you post some of your code snippets?
|
|
|
|
|
I have the following routine:
public static string readHtmlPage(string url) {
string result;
WebRequest request = WebRequest.Create(url);
HttpWebResponse response =(HttpWebResponse) request.GetResponse();
Stream dataStream = response.GetResponseStream();
using (StreamReader reader = new StreamReader(dataStream)) {
result = reader.ReadToEnd();
reader.Close();
}
return result;
}
I email the "result" as the body of an email message but it is loosing its CSS formating. It seems that CSS is never applied can anybody detect something wrong?
|
|
|
|
|
The path to the css is probably relative. As what you have sent in the mail is no longer a page, and has no url, the mail program don't know from where it should load the css.
If you specify a complete url for the css file, it has a possibility to work.
---
b { font-weight: normal; }
|
|
|
|
|
Hm. All of the above is true. So what would return back the complete page?
|
|
|
|
|
Either change the page, or change the contents once you have read the page.
If you have other resources, like images, their addresses have to be changed also. Some resources won't work even if you supply a correct address, like javascript includes.
There is no way that you can keep all functionality when you send the code of a page as a mail. A mail program is not a browser, so it will not support everything that a browser does.
---
b { font-weight: normal; }
|
|
|
|
|
Hi..
How could I confirm user registration by email?
Some websites tell the user that he should Activate his Account
(When he register) By the email he will recieve.
How could I make a similar thread?
I am too late but i will never give up
|
|
|
|
|
This has many way,
i.e : you can send a email to user contain a link whith his userID.
http://www.sample.com/confirm.aspx?userID=150
when user clicked link in this page you can varify userID and active it.
|
|
|
|
|
Thank you very much ..I hope I find an article for this subject.
I am too late but i will never give up
|
|
|
|
|
Hello,
I posted a message here before and I dont now if this is the right forum for me byt the question that I need help with is this.
I have this code. This code shown all the image file I have but I need to rean in the textfile to.
<%
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(Server.MapPath("/test/"))
Set fc = f.Files
For Each f1 in fc
if right(lcase(f1.name),4) = ".gif" then Response.Write(" ")
Next
%>
And I want to read in a textfile with the same namn but is not a *.gif its a *.txt file. This is the response I get.
foreach (string s in System.IO.Directory.GetFiles(@"c:\dir", "*.gif"))
{
string txtPath = s.Substring(0, s.Length - 3) + "txt";
System.IO.TextReader tr = new System.IO.StreamReader(txtPath);
string text = tr.ReadToEnd();
tr.Close();
}
Now how can I make this work. I need to show the image and then the text after the image. There can be many image and text files so I dont now how I should do it. Is there a king on asp that can help med with this?
|
|
|
|
|
Hi there,
Looks like you want to convert the .net code of reading text files into vb script and put it inside the For Each statement of the classic ASP code. The documentation of the FileSystemObject may give you some hints:
FileSystemObject Sample Code [^]
Also, the Web Development[^] is the right room for the classic ASP questions, and here is for the ASP.NET.
|
|
|
|
|
Hello,
I am new to XML Web Services in .NET. I am looking for some of the following few FREE web services which I can use on my website.
Please suggest me some websites where I can get some of these free webservices.
(1)Sending SMS to anywhere in India
(2)Collecting weather information for Indian Cities and Towns
(3)Checking if an e-mail id is valid or not
(4)Any othere utility webservices
Thanks
-Sudhakar
|
|
|
|
|
|
|
Pals, i have two buttons at one form, one to logout and the other one to submit the form, i fill the form like anyone, the problem is when i press the enter button the logout button event start to working, and i want to start to run submit button, its basic but i didnt fix it.
gracias
keep Learning and you never will be out of date...
|
|
|
|
|
Hi,
It looks like you have problem with naming... If you hit Enter Button....Logout Button should never perform any action and vice versa.... Please check the event handling..
hope it works.
Happy Programming.
Sanjeev
|
|
|
|
|
You might want to check if the submit has the focus when you hit the Enter. Anyway, in the ASP.NET 2.0, you can have a look at the HtmlForm.DefaultButton Property[^]
|
|
|
|
|
To access formview editing element in a class function, I can use the following code:
HttpContext.Current.Request.Form("fvwName$elmName")
How can I access gridview editing row element value in a class function?
|
|
|
|
|
+ Get reference to the Page instance by casting the HttpContext.Current.Handler property to the Page .
+ Get reference to the GridView control using the Page instance and the FindControl method.
+ Get reference to the editable row using the properties of the GridView instance that you have in the previous step.
|
|
|
|
|
Could you please post some code sample?
|
|
|
|
|
Below is the sample code for getting the edit row, and once you have the reference you can easily access the edit values from the cells of the row:
public GridViewRow GetEditRow()
{
Page page = HttpContext.Current.Handler as Page;
GridView gridView = page.FindControl("GridView1") as GridView;
GridViewRow editRow = gridView.Rows[gridView.EditIndex];
return editRow;
}
|
|
|
|
|
When I try your code, I got the following error on line GridViewRow editRow = gridView.Rows[gridView.EditIndex];
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
|
|
|
|