|
I have a web form with a table control. No. of columns & no. of rows are asked by user and table is generated with cells filled with textboxes dynamically. The id of textboxes are generated dynamically. User enters the values in textboxes in table & click calculate button, on which I want to supply a set of results based on input data. Can anybody tell me how to fetch the value entered in a textbox at runtime. I am using following code.
public void CreateTableRawData(int rows)
{
for (int i = 0; i < rows; i++)
{
TableRow tr = new TableRow();
TableCell td = new TableCell();
TextBox txt = new TextBox();
td.Controls.Add(txt);
txt.ID = "txt" + i.ToString();
tr.Cells.Add(td);
Table1.Rows.Add(tr);
Table1.Caption = "Raw Data Form";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
int rows = Convert.ToInt32(TextBox_rows.Text.ToString());
double[] data = new double[rows];
string [] dataText = new string[rows];
Table tbl = (Table)Panel1.FindControl("Table1");
for (int i = 0; i < rows; i++)
{
data[i] = Convert.ToDouble(Table1.Rows[i].Cells[0].Text.ToString());
}
data[0] = Convert.ToDouble(Table1.Rows[0].Cells[0].ToString());
Label lbl = new Label();
double sum = DistributionFitting.Statistics.Sum(data);
lbl.Text = sum.ToString();
}
I am getting following error at runtime.
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
|
|
|
|
|
ashutosh_karna wrote: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
As exception shows,you must be accessing some array's index that doesn't hold.Debug it ,you'll be able to get the problem
|
|
|
|
|
Try to debug your application and check which line is throwing the exception. check the index of the array.
One more important thing, you are creating the textboxes runtime. You need to create the textbox before Page_load() . Because in ASP.NET Page life cycle, ViewState Data and PostBack data loads just before the Pageload. So if you create any control after page load you can't restore the postback and view state data.
The best option, try to create your controls in Page_PreInit() Event.
|
|
|
|
|
Hi,
I need to change my web application in such a way that , I need to apply different styles(different css files,different images) for the same pages for different users.So when different users sign in they will see the same pages in different colors .Is it possible
Regards
Jophin
jophin
|
|
|
|
|
I can suggest you two different you implement.
1) ASP.NET Profiles : ASP.NET having inbuilt features to implement it. Please read this article
2) Data Base : Store user choice theme in the database and retreive the data (Theme/css name) from DB while user login an apply it. Update database if user change the reference.
Hope this will help you
|
|
|
|
|
Thank you Abhijeet,
Let me have a try.
Regards
Jophin
jophin
|
|
|
|
|
It is very much possible.Use asp.net Theme for detail Have a look
Save the theme as per user basis in the database and when loading the application read it from database and load the theme accordingly.
|
|
|
|
|
Thank you very much Brij,
I tried this and it works .But still I am having another issue, there are palces in which images are loading from client side.
Because of this I am having two problems.
1. They are not getting loaded because the previous location of images folder is changed are changed.
2. How I can make these images also dynamic according to the theme applied
Thanks in Advance
Jophin
jophin
|
|
|
|
|
jophinmichael wrote: Because of this I am having two problems.
1. They are not getting loaded because the previous location of images folder is changed are changed.
2. How I can make these images also dynamic according to the theme applied
AS you are applying theme Dynamically, it means you are applying either Theme or css to the pages. Create Different CSS which having the different images. So that will resolved your problem.
One more thing try to apply your theme in Page_PreInit() event
Hope this will help you .
|
|
|
|
|
Hi Abhijit,
Sorry for this late reply.I think I did not explained my problem properly.
I tried app themes and it is working fine for me.So I am able to apply different themes according to the users who are signing in.But In my aspx pages there are some html images like the following
. But I wanted to load different images according to the theme which is getting applied.
So now I am planning to do something like the following
for my green theme and
for my red theme and in the class I will provide the src for the image .
I am not sure whether this is the proper way of doing it.
So if this is not the right way can you suggest me a better way.
Regards
Jophin
jophin
|
|
|
|
|
Do as Abhijit says,it'll resolve your problem.Use different css files according to theme and aplly them according the theme
|
|
|
|
|
Hi,
On my form, I have a dropdown list, iframe and a button
Source of Iframe is given by the button click javascript.
My dropdownlist selected item is 0
document.getElementById("MyFrame").src = "http://myapp/processing.aspx?ddl=0" ;
works fine
My dropdownlist selected item is 1
document.getElementById("MyFrame").src = "http://myapp/processing.aspx?ddl=1" ;
works fine
My dropdownlist selected item is 0
document.getElementById("MyFrame").src = "http://myapp/processing.aspx?ddl=0" ;
Doesn't work fine. It somehow remembers this link. When I debug, it doent visit Processing.aspx .Processing page internally redirects to a different page. I find that other page is loaded directly visited.
I always want the processing page to be visited. When I delete the cookies before i again select the drop down list item as 0 then it works fine. What is the remedy of this?
Thanks,
Vijay
|
|
|
|
|
It is difficult to diagnosis the problem with this description. Can you please post the entire javascript code?
|
|
|
|
|
It could be something as simple as making sure the processing page is set to not be cached.
|
|
|
|
|
yes i fixed it by not caching the page
thanks for the help.
vijay
|
|
|
|
|
Seems simple enough....Am using C# VS2008.....just trying to pass the text value of a selected item in a listbox to a text box so it can be evaluated for an SQL statement.
string year = ListBoxYears.SelectedItem.Text;
...but it fails with the following error reported:
NULL REFERENCE EXCEPTION was unhandled by user code:
Object reference not set to an instance of an object.
I am also unable to get the "selectedindexchanged" event to work as it does in C# desktop...that is to say, for it to post a changed value to any other control when a change is made in the list box;
I have tried a number of different techniques to retrieve the string, but all to no avail. I have reset the AutopostBack both on and off...no difference. And I have tried to use all of the different properties and conversion available for a listbox that could have anything to do with a string or that might be converted to a string.....no results. Obviously, my frustration level is at 100% now.
ANY assistance would be greatly appreciated....Pat
|
|
|
|
|
The SelectedItem always null if nothing selected in the listbox. So you have to validate whether the SelectedItem is null before retrieve the value.
PDTUM wrote: I am also unable to get the "selectedindexchanged" event to work as it does in C# desktop
The SelectedIndexChanged event will fire only if you set the AutoPostBack is true.
|
|
|
|
|
Thank you for your reply...I changed the AutoPostBack to true on both controls and have tried every variation of it being on and off. The following error is reported when it runs:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 445: protected void ListBoxTrans_SelectedIndexChanged(object sender, EventArgs e)
Line 446: {
Line 447: TextBoxTrans.Text = ListBoxTrans.SelectedItem.Text;
Line 448: }
Line 449:}
Any other ideas?
|
|
|
|
|
Did you debug the code? Place a break point and find out the origin of error and which object is null.
|
|
|
|
|
Are you populating your list box in the page load by any chance? If so, it could be that you're not checking if the page is posting back. You might need something like this...
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
}
}
|
|
|
|
|
YES YES YES DoctorMick....that DID it. I had the list boxes initially loading in the Page_Load event and it was being confused by the postback. I do not use ASP.NET that often and sometimes have trouble migrating from C# applications....THANK YOU very much.
I am having an issue with WEB Posting on another application, which works perfectly in the desktop browser but is also giving a NULL exception error when is is running online (losing SESSION values). I will be posting that a little later today. I hope you have a moment to give it a look....and thank you all for your responses...much appreciated...Pat
|
|
|
|
|
Yes...with the debug active, the error occurs immediately upon selection of the item in the listbox when the "SelectedIndexChanged" event fires, so selecting an item does trigger the event. It just reports a NULL value even though an item is selected. It seems simple enough and I am thoroughly confused about why.
|
|
|
|
|
We are using AjaxPro2 and have following code:
JSTextTransfer.aspx
<script language="javascript" type="text/javascript">
function Getajaxfunction()
{
var flag = TextTransfer.CallAjaxFunction("Test");
alert(flag.value);
}
</script>
JSTextTransfer.aspx.cs
public partial class TextTransfer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(TextTransfer));
if (!IsPostBack)
{
}
Btn_Ajax.Attributes.Add("onclick", "javascripe:return Getajaxfunction();");
}
[AjaxPro.AjaxMethod]
public string CallAjaxFunction(string atr)
{
return "Test";
}
}
We get the following error:
TextTransfer is undefined.
The page is hosted on a server which has the following directory structure
/htdocs/
/htdocs/bin/AjaxPro2.dll
/htdocs/mysite/JSTextrTransfer.aspx (and .cs)
The tech support says the url which refers AjaxPro has to be changed.
We changed the web.config entries to:
<scriptReplacements>
<file name="prototype" path="http://www.mysite.com/ajaxpro/prototype.ashx" />
<file name="core" path="http://www.mysite.com/ajaxpro/core.ashx" />
<file name="converter" path="http://www.mysite.com/ajaxpro/converter.ashx" />
</scriptReplacements>
Still no luck.
There is a 4th line for ashx in 'view source'.
<script type="text/javascript" src="/ajaxproTextTransfer,App_Web_jstexttransfer.aspx.5d7ed009.aexw4iuf.ashx"></script>
How can this dynamic entry be added in the web.config? Is this what is causing the error?
Or is there any other solution to overcome this?
Thanks in advance.
|
|
|
|
|
What is AJAX Pro ? Do they not have a forum ? I believe most people here use the ASP.NET AJAX extensions.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|