|
I'm tasked with helping a developer finish up a web page that collects information about an order and populates some SQL Server tables. ASPX with C#. I'm not a C# guy, but my main job here is to keep him on task, interface with the dept. that will need this, and validate the data design. At present, there are some issues with postbacks. He does a good bit of validation, mostly to ensure fields aren't blank, and posts back upon exit of a good many fields. One problem is retaining focus after postback. The user enters a value, presses tab, and a postback occurs. Instead of the focus moving to the next field, there seems to be no field with focus after the postback, which forces the user to click in the next field with the mouse. So instead of being able to tab to fields as expected, the user keeps having to use the mouse to get the focus to the appropriate field. This is not very desireable at all. Another issue is what fields cause a postback. An example would be a field that can be empty (zero), but if it's >0 another field needs to be populated. The postback occurs after the first field and an error message is displayed next to the second field saying it can't be empty, yet the user hasn't even had a chance to enter anything in that field. This is most likely a simple fix of where the validation originates from (the second field instead of the first), but the programmer seems to think this is hard to do or not doable. I may have to dig into C#, but some help here would be appreciated.
Thanks,
Russell
|
|
|
|
|
Why are you validating on the server when the user tabs out? I'd keep the "light" validation on the client side with JavaScript and save the postbacks for submitting the form. Then you can set the focus to the field that has errors, or move them on.
That validation you are mentioning should definitely be clientside. Is the developer rolling their own code, or using something supplied by the framework like a RequiredFieldValidator that can be set to dynamic and will run on the clientside without a postback?
If there is some compelling reason why you would roundtrip every time a user leaves a field (which seems to make sense only for a small internal app without many concurrent users, otherwise it won't scale well) then I'd look at using a callback instead of a postback for the validation. They are not complicated to wire in and infinitely improve the user experience while cutting down on the size of network traffic (have you used Fiddler or something similar to see how much data, like ViewState, gets thrown around when you postback?)
|
|
|
|
|
I have been thinking clientside validation is the way to go, also. I'm coming in late to this project and we have a deadline looming on 9/1, so that's a consideration when making changes. I only realized we had this problem yesterday, unfortunately. The page is for external users, but the volume will be low (about 1600 users entering one order each over the period of two - three months). As you can see, the amount of traffic is not really an issue, but serverside validation may not be the way to go due to these other issues. Thanks for your reply.
|
|
|
|
|
Checking for blank fields, etc should definetly be done on the client side.
Here is an example Javascript validation routine:
function valToFormulator() {
if ((document.getElementById('<%=tbxCustomerID.ClientID%>').value == "") ||
(document.getElementById('<%=tbxContactID.ClientID%>').value == "")) {
alert("You must select a contact before sending to the flavor chemist.");
return false;
}
else
return true;
}
On the ASP.NET button, I have the following attribute:
OnClientClick="return valToFormulator();"
If the validation routine returns a "false", then the PostBack does not occur and the validation routine displays the Popup alert box with the error message.
Have your programmer try it out on a simple field validation where a field cannot be blank. You will be much happier with the performance. 
|
|
|
|
|
Hello
My web page has download and upload page. I design the form with text boxes and combo boxes. I want to know what should I write in the code-behind for the button to collect the information from the text boxes and recieve the attached file.
Excuse me for bad english writing.
|
|
|
|
|
If all the controls are Runat=Server
you can directly access the objects in the server side. Like
fileupload.SaveAs("filelocation") //File Upload is asp:FileUpload control
YourTextbox.Text = "Hello"
Hope this helps.
|
|
|
|
|
hasani2007 wrote: I design the form with text boxes and combo boxes
What is the purpose of TextBox and Combo Box over here ?
Use only FileUpload Control To Upload File and Use an Button say Upload. OnClick on that button upload the file.
Use this samle code. Please Check the syntax.
If(FileUplaod1.HasFile)
{
FileUpload1.SaveAs(FilePath);
}
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
|
Hello,
I am having problem in running query for the following code:
Actually My database in in MS Access and I need to compare the date column (which is in Date format in the database) with the value of the Date textbox (which is a string). So maybe I need to convert the string to date format and then compare......should I convert to date format?
My date is stored in the database as dd-mmm-yy. For example it's stored as 31-Aug-09.
Please assist:
public void executePositiveListQuery_ANY(string selected_Date)
{
string sql;
if(selected_Date=="empty")
sql= "SELECT DISTINCT re_MLNO FROM ml_hiv_status WHERE (re_HIV1_Status=1 AND re_HIV2_Status=1)";
else
{
string selectedDate = (Convert.ToDateTime(selected_Date)).ToShortDateStr ing();
sql= "SELECT re_MLNO FROM ml_hiv_status WHERE ( re_SpecimenDate='" + selectedDate + "' AND re_HIV1_Status=1 AND re_HIV2_Status=1)";
resultsLabel.Text ="You Have selected"+ selectedDate;
}
try
{
OleDbConnection connection = new OleDbConnection(HIV.Database.DataConstants.CONNECT ION_STRING);
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(sql, connection);
DataSet ds = new DataSet();
adapter.SelectCommand = command;
int count = adapter.Fill(ds);
if (count > 0 && count <= 200)
{
DataView view = ds.Tables[0].DefaultView;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDatagrid.Visible = true;
resultsLabel.Text = count.ToString() + " results found.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = true;
}
else if (count> 200)
{
DataView view = ds.Tables[0].DefaultView;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDatagrid.Visible = false;
resultsLabel.Text = "More than 200 results found. Please Click the Export to Excel Link to Download the Results.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = true;
}
else
{
resultsLabel.Text = "No results found.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = false;
resultsDatagrid.Visible = false;
}
connection.Close();
}
catch(Exception ex)
{
message.InnerHtml = "SQL: " + sql + "<p></p>" + ex.ToString(); here!!
}
|
|
|
|
|
The best thing to do would be to parameterise the query so the conversion work is done for you.
Failing that, converting the date format in your query string to either yyyy-mm-dd or dd mmm yyyy should do the trick.
|
|
|
|
|
How would I do that? Can you please help?
|
|
|
|
|
|
OledbParamenter @yourtime
|
|
|
|
|
I created a Web User Control that contains an HTML Input Box. On my web page I have added this Web User Control. In the page_load of the code behind of my web page how can I set a default value to the Input box?
|
|
|
|
|
Set the value property of the input box in user control.
Or do you want to set it at page load?
|
|
|
|
|
I want to set the value at page load.
|
|
|
|
|
Create a public set property in the user control and then use it from main page to set the value in textbox.
|
|
|
|
|
your html controller:
<intput: type=" Button" text="<%some" public%="">>
server page :
UserController.somepublic=yourValue;
|
|
|
|
|
input type="Button" text=<%some public%>
|
|
|
|
|
Hello Friends,
I'm creating custom paging. Everything is working fine but there is a problem actually
i'm displaying for four pages at a time i.e. 1,2,3,4 and a Next for moving on next pages.
But as i click on Next button it's bringing correct records and correct paging control.
But now if i click on any New page buttons that's n't working i have to press page button
two times to work on.
for example if i've to view Page No. 6 then i've to press Page No. 6 two times
http://autoneed.in/Rough/Paging.aspx[^]
|
|
|
|
|
Hi,
Would you mind pasting you code here?
That will help people where the issue is, this is some logical mistake I guess so.
|
|
|
|
|
When you click on Next button the "page no, Next" text is set in the link title, is that anything to do with the logic?
When you click on page no link, same text is replace by "Page no, Paging No.".
|
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
{
//Keep at top because it specifies the total no. of records available in the table
if (!Page.IsPostBack)
{
//Current Page No.
ViewState["Current_PNo"] = 1;
//State Page No.
ViewState["Current_Start"] = 1;
//Last Page No.
ViewState["Current_Last"] = 4;
//lblMsg.Text = ViewState["Current_Start"].ToString() + "," + ViewState["Current_Last"].ToString();
//Set MaxRow
ViewState["MaxRow"] = 10;
//startNo and maxNo
bindDataList(1, int.Parse(ViewState["MaxRow"].ToString()));
//Creates the paging nos i.e. 1,2,3,4
createPagingControl(int.Parse(ViewState["Current_Start"].ToString()),int.Parse(ViewState["Current_Last"].ToString()));
}
else
{
int start = Convert.ToInt32(ViewState["Current_Start"].ToString());
int last= Convert.ToInt32(ViewState["Current_Last"].ToString());
createPagingControl(start,last);
}
}
public void bindDataList(int startRow,int maxRow)
{
using (SqlConnection mCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
{
int maxRow_New = startRow + maxRow;
Session["MaxRow"] = maxRow_New.ToString();
//string strsql = "Select * From Table2 Where Active=1 and ID>="+startRow+" and ID<="+maxRow_New+" ";
string strsql = null;
strsql="Select *,Total=(Select Count(*) From Table2 Where Active=1) "+
"From Table2 Where Active=1 and ID>="+startRow+" and ID<="+maxRow+" ";
SqlCommand mDataCom = new SqlCommand();
mDataCom.Connection = mCon;
mDataCom.CommandText = strsql;
mDataCom.CommandType = CommandType.Text;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(mDataCom);
da.Fill(ds);
PagedDataSource page = new PagedDataSource();
page.AllowPaging = true;
//Set Total No. of Rows in the Database
ViewState["RowCount"] = ds.Tables[0].Rows[0]["Total"].ToString();
//Set maxRow
page.PageSize = int.Parse(ViewState["MaxRow"].ToString());
page.DataSource = ds.Tables[0].DefaultView;
//DataList1.DataSource = ds.Tables[0];
DataList1.DataSource = page;
DataList1.DataBind();
}
}
public void createPagingControl(int start,int last)
{
int rowCount = Convert.ToInt32(ViewState["RowCount"].ToString());
PlaceHolder1.Controls.Clear();
if (rowCount / int.Parse(ViewState["MaxRow"].ToString()) >= last)
{
for (int i = start; i <= last; i++)
{
LinkButton lnk = new LinkButton();
lnk.Text = i.ToString();
lnk.ToolTip = i.ToString() + ", Paging No.";
lnk.Click += new EventHandler(lnk_Click);
Label lbl = new Label();
lbl.Text = " ";
PlaceHolder1.Controls.Add(lnk);
PlaceHolder1.Controls.Add(lbl);
lnk.Style["text-decoration"] = "underline";
lnk.Style["Color"] = "DarkBlue";
lnk.Enabled = true;
}
}
}
public void lnk_Click(object sender, EventArgs e)
{
LinkButton lnk= sender as LinkButton;
lnk.Style["text-decoration"] = "none";
lnk.Style["Color"] = "Maroon";
lnk.Enabled = false;
int currentPage = int.Parse(lnk.Text);
//Multiply by maxRow
int maxRow = currentPage * int.Parse(ViewState["MaxRow"].ToString());
int startRow = currentPage == 1 ? 1 : maxRow - (int.Parse(ViewState["MaxRow"].ToString())-1);
bindDataList(startRow, maxRow);
}
public void lnkClick(int cureentPage)
{
//LinkButton lnk = sender as LinkButton;
LinkButton lnk = new LinkButton();
lnk.Text = cureentPage.ToString();
lnk.Style["text-decoration"] = "none";
lnk.Style["Color"] = "Maroon";
lnk.Enabled = false;
int currentPage = int.Parse(lnk.Text);
//Multiply by maxRow
int maxRow = currentPage * int.Parse(ViewState["MaxRow"].ToString());
int startRow = currentPage == 1 ? 1 : maxRow - (int.Parse(ViewState["MaxRow"].ToString()) - 1);
bindDataList(startRow, maxRow);
}
protected void lnkNext_Click(object sender, EventArgs e)
{
int start= Convert.ToInt32(ViewState["Current_Last"].ToString())+1;
int last = Convert.ToInt32(ViewState["Current_Last"].ToString()) + 4;
ViewState["Current_Start"] = start.ToString();
ViewState["Current_Last"] = last.ToString();
lblMsg.Text = ViewState["Current_Start"].ToString() + "," + ViewState["Current_Last"].ToString();
int currentPage = int.Parse(ViewState["Current_Start"].ToString());
ViewState["Empty"] = start.ToString();
lnkClick(currentPage);
createPagingControl(start,last);
//lblMsg.Text = "Next Clicked";
}
|
|
|
|
|
How can i use custom class a profile i have class
namespace MyCompany.CodeBlog{
[Serializable]
public class UserProfile
{
private string userid;
private string ipAddres;
private string name;
public static UserProfile GetUserProfile(string username)
{
return Create(username) as UserProfile;
}
public static UserProfile GetUserProfile()
{
return Create(Membership.GetUser().UserName) as UserProfile;
}
[SettingsAllowAnonymous(false)]
public string UserId
{
get
{
return userid;
}
set
{
userid = value;
}
}
[SettingsAllowAnonymous(false)]
public string IpAddress
{
get
{
return ipAddres;
}
set
{
ipAddres = value;
}
}
[SettingsAllowAnonymous(false)]
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
}
And i want to use this a profile in my web config file i have
< profile enabled="true">
< properties>
< add
name="UserProfile"
type="MyCompany.CodeBlog.UserProfile" />
< / properties >
< / profile >
in my login page after validating the user i used
Profile.UserProfile.UserId = "1";
Profile.UserProfile.Name = "myname";
Profile.UserProfile.IpAddress = "myip";
but in another page
if (Request.IsAuthenticated)
{
//Error here
string mystr = Profile.UserProfile.Name;
//mystr is null
}
So please guide me if i am completely wrong or i have missed some thing i dont want tto use propfile property in webconfg file
|
|
|
|
|
Try calling: Profile.Save(); after setting values for your profile...
|
|
|
|