I am converting a string that is being read from a textbox in gridview
int numTC = Convert.ToInt32(((TextBox)row.FindControl("numTC")).Text);
However it is returning the following exception:
Input string was not in a correct format.
Can anyone see anything wrong in the conversion?
Thanks
Make Sure that your gridview can accept only numbers you can have a filterextender using ajax and I m sure u will do that what else you can do is to check whether you have a textbox is null or not using the Function given below
if(string.IsNullOrEmpty(((TextBox)Row.FindControl("numTC")).Text))
{}
((TextBox)GridViewname.Rows[e.RowIndex].FindControl("numTC")).Text;
and
use this extender or u can use javascript as well
If it is going inside the if statement that means the value is null
if(!string.IsNullOrEmpty(((TextBox)row.FindControl("numTC")).Text)) {}
I have used ! sign now it will go inside the if statement if there is some value in it.
and try to convert this text into integer using try catch block if u get any exception you can take whatever action you want to.
Let me know if it is complete
It is obvious that the value of the returned in the "Text" property of the text box cannot be converted to inter, I guess you have to insure first that you are returning the correct textbox and that it contains a valid value before attempting the conversion.
Related
I am using the following Codes to get the date from the date picker
objDD_ml.EffDate=(DirectCast(drv.Cells(3).FindControl("rdpEffDate"), RadDatePicker).DateInput).ToString
But it does not return the date... It returns like 'DateInput'
How can i use the code to get the value for Effdate as a correct format of date
Anyone please help me..
Whenever you want date into string and in specific format you can always apply following :
objDD_ml.EffDate = (
DirectCast(drv.Cells(3).FindControl("rdpEffDate"), RadDatePicker).DateInput
).ToString("dd/MM/yyyy")
Try to cast the FindControl object into the corresponding ASP control externally. Then access the value of that control and convert it to .ToString
I don't know what control you are using, but it should be something like below -
objDD_ml.EffDate = ((RadDatePicker)(drv.Cells[i].FindControl("rdpEffDate")).SelectedDate.Tostring;
Does anyone know that how to store a double type value from html textbox into a c# variable?
I have a html textbox with Id txtCost and that will hold a double value.
Thanks in advance.
You need to parse the value using double.Parse() like so:
var value = double.Parse(txtCost.Text);
Although parsing numerical values has some globalization caveats (like how it parses dots and commas). You can read more about the parse method at MSDN
Double val=Convert.ToDouble(txtCost.Text);
Is it possible to put a character sequence in a Filtered TextBox Extender in Asp.NET? My guess is no, but I'm curious. I want the user to be able to enter the characters (such as & and #), but not enter the invalid sequences (such as &#).
Why not just use a regular expression? Because when the form is submitted, all the fields are passed to the server...including fields that are not part of the validation group. These fields do not get checked and may trigger the "A potentially dangerous Request.Form value…”, aka the HttpRequestValidationException. And preventing that message is the whole point of this. I'd rather tell the user, with a regex validator, what they are doing wrong...but I will settle for preventing them from typing the bad chars (&#, <, >).
Edit: sort of an afterthought, but if there's a better way to prevent ALL TextBoxes from including the characters, that'd be great!
You can just have a function onkeydown for all your text boxes and that checks the character pressed and if it's invalid just remove that last character. Also for your combination strings you can just check to see if the previous characters make it invalid then remove all of them.
An example of that type of function is:
function checkKey(event) {
var code = event.keyCode;
// code is the ascii number of the key.
}
url:http://localhost:51806/fair/PersonPage/personalPages.aspx?idCompany=1338006699#Site/AboutAs
request["idCompany"];
this code return null
how can get value idCompany
EDIT
Request.UrlReferrer.Query
this return ?idCompany=1338006699
this Request.UrlReferrer.Query.Split('=')[1] return 1338006699
but i think this way does not good way
#Site/AboutAs is a tab aboutAs in full tab component
Try this instead:
string id = Page.PreviousPage.Request.QueryString["idComapny"];
If no luck then your method of splitting is the best you can achieve, as you're trying to read the query string of the referrer page.
One work around though is to store the value in that previous page.
To do this, store the value of Request["idComapny"] in the previous page, where it should be available, in Session then you can read the Session value in any other page.
i have a project for uploading video.in that when i click the showvideo button there is a error.
code-
param name="url" value='<%# "VideoHandler.ashx?FileID=" + Eval("FileID") %>'
error message ::: conversion form string="VideoHandler.ashx?FileID=" to type 'Double' is not valid
anyone knows please answer for me thank you
"VideoHandler.ashx?FileID=" is a string. Eval("FileID") results in a double. You have a type mismatch, so the addition overload doesn't know how to proceed. Solve it like this:
string.Format("VideoHandler.ashx?FileID={0}", Eval("FileID"))
Without seeing the code, it sounds like you are trying to convert a string which isn't a valid double. Are you taking the value of the query string and trying to convert it or, could you have accidentally tried to convert the page name along with the query string? Based on the short error message you gave, that is what it looks like. If you post the code which is doing the conversion, that will likely make it clearer what is going on, but that is my best guess at the moment.
You are trying to convert a string which is not a valid double type.
I think you are trying to convert the FileID field to double. Then you can split the string and then convert only the FileID part of it.
You can get the querysting data using
Request.QuerySting["FileID"] and then convert it to double.
or use
Double.TryParse Method
We should see some code. Apparantly the application is trying to convert "VideoHandler.ashx?FileID=" to a Double value which cannot be done.
Just add ToString() to the end of your Eval. FileId is a double, and it's seeing the + and trying to add it to a string, numerically, instead of concatenating it.