Tourist_Search
asked on
Page validation works once but not twice then text box lose value
Hi
I'm trying to validate an update form that has data from the db,
The problem is when I delete the text in the text box and click submit I get the message "title required" which is correct. But if I click submit again without filling in the text box I lose all the data in all the text boxes.
Can anyone help solve this problem for me.
*********** Code ****************
<script runat="server">
string strUserName, strPassword;
void Page_Load(Object Src, EventArgs E)
{
Session["strUserName"] = Request.Form["Username"];
Session["strPassword"] = Request.Form["Password"];
if (IsPostBack)
{
Page.Validate();
if(Page.IsValid)
{
Response.Redirect("confirm ation.aspx ");
}
}
}
</script>
<asp:textbox MaxLength="25" id="Company" text='<%# CustDetails.FieldValue("He adline", Container) %>' TextMode="SingleLine" Columns="32" runat="server" />
<asp:RequiredFieldValidato r ControlToValidate="Company " Display="Dynamic" EnableClientScript="true" ErrorMessage="" ID="strValCompany" runat="server" Text="Title required" />
<asp:RegularExpressionVali dator ControlToValidate="Company " Display="Dynamic" EnableClientScript="true" ErrorMessage="" ID="strRegCompany" runat="server" Text="Max 20 characters" ValidationExpression="(.|\ n){0,20}" />
Thanks
George
I'm trying to validate an update form that has data from the db,
The problem is when I delete the text in the text box and click submit I get the message "title required" which is correct. But if I click submit again without filling in the text box I lose all the data in all the text boxes.
Can anyone help solve this problem for me.
*********** Code ****************
<script runat="server">
string strUserName, strPassword;
void Page_Load(Object Src, EventArgs E)
{
Session["strUserName"] = Request.Form["Username"];
Session["strPassword"] = Request.Form["Password"];
if (IsPostBack)
{
Page.Validate();
if(Page.IsValid)
{
Response.Redirect("confirm
}
}
}
</script>
<asp:textbox MaxLength="25" id="Company" text='<%# CustDetails.FieldValue("He
<asp:RequiredFieldValidato
<asp:RegularExpressionVali
Thanks
George
ASKER
Hi x_com
I need the Sessions for another page so I save them on this page
EnableViewState is not turned off
If I have a normal text box with no database column in then that does not lose it's value.
Only the text boxes that have database columns in them lose their values.
George
I need the Sessions for another page so I save them on this page
EnableViewState is not turned off
If I have a normal text box with no database column in then that does not lose it's value.
Only the text boxes that have database columns in them lose their values.
George
Tourist_Search,
Why not just bind the db field value in your code.
eg:
<asp:textbox MaxLength="25" id="Company" TextMode="SingleLine" Columns="32" runat="server" />
void Page_Load(Object Src, EventArgs E)
{
if(!Page.IsPostBack)
{
BindData();
}
}
void BindData()
{
//bind data into all textboxes
DataRow drData;
DataSet dstData;
SqlDataAdapter dadData;
'....your db connection - retrieve value from db
dadData.Fill(dstData,"tabl eName");
drData=dstData.Tables["tab leName"].R ows[0];
Company.Text=drData["Headl ine"].ToSt ring();
//...more textbox here ....
}
Why not just bind the db field value in your code.
eg:
<asp:textbox MaxLength="25" id="Company" TextMode="SingleLine" Columns="32" runat="server" />
void Page_Load(Object Src, EventArgs E)
{
if(!Page.IsPostBack)
{
BindData();
}
}
void BindData()
{
//bind data into all textboxes
DataRow drData;
DataSet dstData;
SqlDataAdapter dadData;
'....your db connection - retrieve value from db
dadData.Fill(dstData,"tabl
drData=dstData.Tables["tab
Company.Text=drData["Headl
//...more textbox here ....
}
ASKER
Hi x_com
Tried databinding but receive an error saying text boxes do not allow databinding
George
Tried databinding but receive an error saying text boxes do not allow databinding
George
ASKER
Hi x_com
I have found the problem, it my style sheet. It is used for the layout of the table if I remove the ID selector for the table it works OK, if I add it back it does't work. This is very strange
George
I have found the problem, it my style sheet. It is used for the layout of the table if I remove the ID selector for the table it works OK, if I add it back it does't work. This is very strange
George
Sorry for my delay, Tourist_Search. My pc infected by a virus and now just recover ..(long story)...
>>Tried databinding but receive an error saying text boxes do not allow databinding
-Textbox not support it, but you can assign any value from db using Text property (please refer my previous solution).
>>I have found the problem, it my style sheet. It is used for the layout of the table if I remove the ID selector for the table it works OK, if I add it back it does't work. This is very strange
-Not familiar with DMX, maybe you know what happend...
Regards
x_com
>>Tried databinding but receive an error saying text boxes do not allow databinding
-Textbox not support it, but you can assign any value from db using Text property (please refer my previous solution).
>>I have found the problem, it my style sheet. It is used for the layout of the table if I remove the ID selector for the table it works OK, if I add it back it does't work. This is very strange
-Not familiar with DMX, maybe you know what happend...
Regards
x_com
ASKER
Hi X_com
No idea why style sheet would effect the post back, but since removing the id selector "#SubmissionUpdateForms" it works OK
I think it has been one off those days
George
No idea why style sheet would effect the post back, but since removing the id selector "#SubmissionUpdateForms" it works OK
I think it has been one off those days
George
Tourist_Search ,
>>No idea why style sheet would effect the post back, but since removing the id selector "#SubmissionUpdateForms" it works OK
-It this css build by yourself? Maybe this css content itself cause the problems. Check it again.
>>No idea why style sheet would effect the post back, but since removing the id selector "#SubmissionUpdateForms" it works OK
-It this css build by yourself? Maybe this css content itself cause the problems. Check it again.
ASKER
Hi x_com
Sorry for the delay in getting back to you. I found the problem, its the firewall I'm using. I have add blocking enabled and it blocking certain words i.e I have tried to create a folder called advertise and it would not work when trying to view it in the browser. Then I remenbered I have add blocking enabled so I disabled it and now the folder works. as well as the ID selector.
Moto of this story, watch what you call names in your code because if the person has add blocking enabled on their computer they may not find certain pages.
What can I do for this question as I would like to award you some points for replying to the question.
George
Sorry for the delay in getting back to you. I found the problem, its the firewall I'm using. I have add blocking enabled and it blocking certain words i.e I have tried to create a folder called advertise and it would not work when trying to view it in the browser. Then I remenbered I have add blocking enabled so I disabled it and now the folder works. as well as the ID selector.
Moto of this story, watch what you call names in your code because if the person has add blocking enabled on their computer they may not find certain pages.
What can I do for this question as I would like to award you some points for replying to the question.
George
No problem.
ASKER
Hi x_com
Are you busy
George
Are you busy
George
Not really, Tourist_Search.
Why?
Why?
ASKER
Hi X_com
Thanks for the reply, I posted a question last night, this morning but the answers seem to have gone cold. I was wondering if you where not busy if you could take a look at it for me and see if you could find what the problem is.
George
Thanks for the reply, I posted a question last night, this morning but the answers seem to have gone cold. I was wondering if you where not busy if you could take a look at it for me and see if you could find what the problem is.
George
Tourist_Search,
Which thread?
Which thread?
ASKER
Hi x_com
The thread is: https://www.experts-exchange.com/questions/20987675/WebClient-Class.html#11056796
I posted the entire page which is causing the problem at the bottom.
Thanks
George
The thread is: https://www.experts-exchange.com/questions/20987675/WebClient-Class.html#11056796
I posted the entire page which is causing the problem at the bottom.
Thanks
George
Tourist_Search,
Found some bugs and fix it. See the solutions there.
Regards
x_com
Found some bugs and fix it. See the solutions there.
Regards
x_com
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for your assistance, modulo.
>>But if I click submit again without filling in the text box I lose all the data in all the text boxes.
-Does others web control TextBox asp.net rather than normal textbox<input type="text"/>
It sure be work. Have you turn off EnableViewState in any place like web.config?
What is the purpose of Session["strUserName"] and Session["strPassword"]? Can i see how you bind to textbox? Why not use Company.Text=yourDataSet.R