Invalid postback or callback argument.
I came across the post on Forums ie:
page_Load() eventIf (!IsPostBack){// bind the data}
I came across the post on Forums ie:
page_Load() eventIf (!IsPostBack){// bind the data}
Now , i am going to explain how to check Whether the Querystring is present or available or not.
For ex: I am passing id as a querystring to the page2.aspx from page1.aspx.
So on Page1.aspxError : Object Reference Exception.Button1_Clickevent() Response.Redirect("page2.aspx?id=1",false); Then on Page2.aspx Page2_Loadevent() If(!IsPostback) { If(!String.ISNullOrEmpty(Request.QueryString["id"])) { // get the value of Querstring id , if id is not null or empty } else if(!String.ISNullOrEmpty(Request.QueryString["name"])) { // get the value of name querystring if name is not null or empty } } When you run the above code - ie: on Page2.aspx you can get the id Querystring value. this works fine.Suppose if you pass some other querystring name ex: name from the Page1.aspx the above code givesie: Button2_Clickevent()Response.Redirect("page2.aspx?name=Dotnet",false);
Page2_Loadevent()If(!IsPostback) { if(Request.QueryString["id"] != null) { If(!String.ISNullOrEmpty(Request.QueryString["id"])) { // get the value of Querstring id , if id is not null or empty } } if ((Request.QueryString["name"] != null) { if(!String.ISNullOrEmpty(Request.QueryString["name"])) { // get the value of name querystring if name is not null or empty } } }
Now i have to show how to set the Autocompletetype - off for the asp.net - Texbox
If you want to set the autoComplete property off use AutoComplete="off" for the textbox.
ie: Autocomplete in the sense if the user typed some text on the textbox, then once again he entered the some word starting with the same letter, it shows previos typed word shows like a combobox manner.
To avoid showing that previous typed word by setting the autoComplete ="Off" to the Textbox.
if you want to set it for the whole page set it on the Form tag
We are going to see how to Edit , Delete , update Gridview rows , when the Gridview is binded through Bound Column.
BoundField in Grid view and bind the data to each field using "Edit Column" option in smart tag of grid view.
We can also add images to Edit and Delete option in Grid view "edit columns" by adding a "commandfield".
This is the Code , here i have take some sample table to do this operation.
String con1 = ConfigurationManager.ConnectionStrings["con"].ToString();
DataSet ds = new DataSet();
To Edit Row
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bindata();
}
To Update the Rows :
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string i = GridView1.DataKeys[e.RowIndex].Value.ToString();
int j = Convert.ToInt32(i);
TextBox t1 = new TextBox();
t1 = (TextBox)GridView1.Rows[e.RowIndex].Cells [0].Controls [0];
TextBox t2 = new TextBox();
t2 = (TextBox)GridView1.Rows[e.RowIndex].Cells [1].Controls [0];
TextBox t3 = new TextBox();
t3 = (TextBox)GridView1.Rows[e.RowIndex].Cells [2].Controls [0];
SqlConnection con = new SqlConnection(con1);
string upt = "update Allergies set Allergy = @allergy, Symptoms = @symptom, Action_to_be_taken =@action where Allergy_id=" + j;
SqlCommand cmd = new SqlCommand(upt, con);
cmd.Parameters.Add("@allergy", SqlDbType.VarChar).Value = t1.Text;
cmd.Parameters.Add("@symptom", SqlDbType.VarChar).Value = t2.Text;
cmd.Parameters.Add("@action", SqlDbType.VarChar).Value = t3.Text;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
bindata();
}
To Cancel the Edit rows :
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bindata();
}
To Delete the Rows :
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string i = GridView1.DataKeys[e.RowIndex].Value.ToString();
int j = Convert.ToInt32(i);
SqlConnection con = new SqlConnection(con1);
string del = "Delete from Allergies where Allergy_id=" + j;
SqlCommand cmd = new SqlCommand(del, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
bindata();
}
Today , we are going to discuss about the Regular Expression for Indian Phone Numbers.
Default there is only few Regex available on .net Regularexperssion validator controls.
so if we want to validate our textbox field like indian phone numbers, landline number we have write it own Expression.
There is expression tools available to - Check the Expression is valid or not. I have no idea about this because i have not used.
To accept Indian (Landline) phone numbers check this Regex : /^[0-9]\d{2,4}-\d{6,8}$/
This is indian phone number. where it will take a format of std code 3 to 4 digits, hypen and rest of the 6 to 8 digits.
Ex: 0222-8345622 or 09786-567567
This one is for eight digit no :: \d{8} eg: 26440050
This one is for mobile no:: \d{10} eg: 9998945678
This one is for mobile no with india code \d{13} eg 9109998945678
This one is for Mobile no with india code then space and then mobile no whith zero as starting :: +\d{2}\s\d{9} eg:+91 09998945678
Here is the another article ie: which is going to find the emailID on the Text File and assign to a string.
Here i have the Textfile ie: Notepad File on the Server folder.
in the notepad file i have some content and emailID too, so i want to get the EmailID from the file so i have to send email to that user.
For this i am using REGEX so its easy to find the emailID on the text file and add or store it on arrays.
Here i am using the Two Method both are using REGEX pattern.
Here you go.. I tested - its working fine.
First Method:
using System.Text.RegularExpressions;
using System.IO;
try
{
//the file is in the root - you may need to change it
string filePath = MapPath("~") + "/EmailText.txt";
using (StreamReader sr = new StreamReader( filePath) )
{
string content = sr.ReadToEnd();
if (content.Length > 0)
{
//this pattern is taken from Asp.Net regular expression validators library
string pattern = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
MatchCollection mc = Regex.Matches(content, pattern);
for (int i = 0; i < mc.Count; i++)
{
//here am just printing it.. You can send mails to mc[i].Value in thsi loop
Response.Write(mc[i].Value + "
");
}
}
}
}
catch (Exception ee)
{
Response.Write(ee.Message);
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Second Method:
string pattern = @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(pattern);
//Read file
string sFileContents =System.IO.File.ReadAllText(Server.MapPath("Email.txt"));
System.Text.RegularExpressions.MatchCollection mc = reg.Matches(sFileContents);
//string array for stroing
System.Collections.Generic.List str = new System.Collections.Generic.List();foreach (System.Text.RegularExpressions.Match m in mc)
{
str.Add(m.Value);
}
OUTPUT
input file
----------
jeevan@test.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it ,
Welcome yo Hyderabadtechies.info
test@test.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it ,
its really cool....
Chandrasekarthotta@gmail.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it
sdf
sdfs
dfsd
output :
jeevan@test.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it , test@test.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it , Chandrasekarthotta@gmail.com
Here I am going to discuss about the - Difference between typeof and GetType ? - typeof and GetType produce the exact same information. But the difference is where they get this information from:
* typeof is used to get the type based on a class. That means if you use typeof with object, it will gives you error. You must pass class as parameter.
* Where GetType is used to get the type based on an object (an instance of a class). Means GetType needs parameter of object rather than class name.
You can understand more with example.
The following code will output “True”:
string instance = “”;
Type type1 = typeof(string);
Type type2 = instance.GetType();
Console.WriteLine(type1 == type2);
Now i am going ot discuss about how to Generate 16 digit Unique number
So ,
5 digit Random using System.Random Class
5 digit number by using TimeSpan
6 numbers by System Time (HH:MM:SS)
This is the Code
System.Random fiveRandom = new Random();
TimeSpan tsFive = new TimeSpan();
tsFive = DateTime .Now.Subtract (Convert.ToDateTime ("01/01/1900"));
string rad = fiveRandom.Next(10000, 99999) + tsFive.Days.ToString() + System.DateTime.Now.Hour.ToString ("00") + System.DateTime.Now.Minute.ToString ("00") + System.DateTime.Now.Second.ToString ("00") ;
Here i am going to share
1) How to Compare two Datetime object ( here i am mentioning some ways to Compare Datetime Variables )
2) How to get the timeSpan Values from the Hours and add hours to the Datetime its easy.
My site is worth$16,159.24Your website value?