|
I’ve got a simple page that should display the string “OK” when the user clicks the button. It works fine untill I put a RequiredFieldValidator on the page. Now it seems like there is an implicit conditional in the source code that prevents the “OK” from being displayed unless the text box has text in it. I put no such conditional in the code; why is it behaving like this?
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="pageIsValidTest.aspx.vb" Inherits="pageIsValidTest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Textbox:
<asp:TextBox ID="TextBox" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox"
ErrorMessage="enter text"></asp:RequiredFieldValidator><br />
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
Label:
<asp:Label ID="Label" runat="server"></asp:Label></div>
</form>
</body>
</html>
Partial Class pageIsValidTest
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label.Text = "OK"
End Sub
End Class
|
|
|
|
|
That is because the RequiredFieldValidator has the ControlToValidate set to the text box. It is working as it should, if no text is in the ControlToValidate the RequiredFieldValidator will prevent your server side code from running.
|
|
|
|
|
Thanks! Didn’t mention that in the book I’m using so I was confused.
But then what is the point of Page.IsValid? If the server side code will only run if all Validators are true then it seems that it would be impossible to get a false Page.IsValid…
What if I want server side code to do something if the form isn't valid, is there a way to override this behavior?
|
|
|
|
|
You can change the "Causesvalidation" of your button to "False" , so it will work without fire the Validators.
i hope it help you.
|
|
|
|
|
Thanks you for the response but not quite what I am looking for. I’m looking for a way to run the source code and within that source code programmatically determine if the page is valid (meaning a validaters = true) and do something it is and something else if its not.
|
|
|
|
|
ok. But you must be more explicit,ex: what are you doing in the page before you do that request?
|
|
|
|
|
Page.IsValid is used to check the validation status at server side. Validation control uses JS by default to do the validation. Since JS is not reliable, ASP.NET does server side validations also to make sure validation logic is not bypassed and set the IsValid flag. So before you continue with your action, check the page is valid. Something like
If(this.IsValid)
bigmish2 wrote: I’m looking for a way to run the source code and within that source code programmatically determine if the page is valid (meaning a validaters = true) and do something it is and something else if its not.
When validator controls are added, by default the validation will happen at the client side. So validating programatically at server side is pointless as form will not postback if there are validation errors. To do the validations on server, you have to disable client side validations first. Set the EnableClientScript property of the validation control to false .
Page class exposes a Validators[^] collection where you can iterate and call Validate() method on each validator to perform the validation. Check the IsValid property to get the status of validation.
|
|
|
|
|
I think I got it now. So if I leave EnableClientScript as true for all validators the code in the source code will only run if all validators are true; the only reason to put Page.IsValid conditional in the source code in this case would be to make sure that the form elements are actually valid and some how the client side validation wasn’t erroneous or by-passed by a user.
If I wanted to do a source code conditional based on form element validity I should set EnableClientScript to false so that the source code will still run even if the user enters in invalid entries.
Thanks all, M
|
|
|
|
|
Hi,
I need to get total size of sessions in my application, I enabled the trace for a page, but it didn't show anything about size of sessions.
How can I get it?
Best wishes
|
|
|
|
|
mehrdadc48 wrote: I need to get total size of sessions in my application
That'd odd. Why do you want to do that? You can't calculate the actual size of objects.
|
|
|
|
|
The classic question is, Does size matters?
|
|
|
|
|
By any chance, do you mean to say number of sessions?
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
hi to all,
I have
button1
and
updatepanel->
Modalpopup Extender->
panel->asp.net controls(UserControls+WebControls)
now when i click on button1 it opens modalpopup but i want to set the tabindex for the controls which are present inside the modalpopup extender
and
the first control i have is usercontrol now
how to set tabindex for this one..
i tried the following one but it is not working
i.e,
Button1_Click(Object Sender,EventArgs e)
{
modalpopupextender1.show();
txtstudent.mandatorytabindex=1 //mandatorytabindex is property of usercontrol and txtstudent in usercontrolname
txtstudent.Focus();
//the above two are not working
}
try to solve this issue.
Regards,
Koti.K
|
|
|
|
|
did you debug your code?
What properties are set in aspx page for ModalPopup?
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
Hi
I set the below properties to modalpopup extender
Enabled=True
TargetControlID=btnHidden //<id of the button>
That's all
|
|
|
|
|
then you button_Onclick event will not be reached. What happens if you do not use the TargetControlID?
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
Hi
If i dont Give targetcontrolid to Modalpopup it won't accept anything
and it shows an error msg like .......modalpopup extender should have targetcontrolid.....
Regards
Koti
|
|
|
|
|
can't you add a button to your page with visible=false and set that as targetcontrolid ?
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
Eventhough the button visible is set to false or true, the button willnot be visible on the page. so there is no problem with Button.
i don't think the problem is with Button(visible=true or visible=false).
Need for me is how to set the tabindex.
Koti.K
|
|
|
|
|
hi i m using asp.net when i edit any feild it will generate a error.
code is
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="material_issueno"
Style="position: relative;" AllowPaging="True" PageSize="20" AutoGenerateEditButton="True" OnRowEditing="GridView1_RowEditing1" CellPadding="4" ForeColor="#333333" GridLines="None">
<Columns>
<asp:BoundField DataField="material_issueno" HeaderText="material_issueno" InsertVisible="False"
ReadOnly="True" SortExpression="material_issueno" />
<asp:BoundField DataField="materialissue_date" HeaderText="materialissue_date" SortExpression="materialissue_date" />
<asp:BoundField DataField="qty" HeaderText="qty" SortExpression="qty" />
<asp:BoundField DataField="sno_to" HeaderText="sno_to" SortExpression="sno_to" />
<asp:BoundField DataField="sno_from" HeaderText="sno_from" SortExpression="sno_from" />
<asp:BoundField DataField="issue_to" HeaderText="issue_to" SortExpression="issue_to" />
<asp:BoundField DataField="issue_by" HeaderText="issue_by" SortExpression="issue_by" />
<asp:BoundField DataField="clientname" HeaderText="clientname" SortExpression="clientname" />
<asp:BoundField DataField="entered_by" HeaderText="entered_by" SortExpression="entered_by" />
<asp:BoundField DataField="ptypename" HeaderText="ptypename" SortExpression="ptypename" />
<asp:BoundField DataField="remarks" HeaderText="remarks" SortExpression="remarks" />
<asp:BoundField DataField="invoice" HeaderText="invoice" SortExpression="invoice" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:inventryConnectionString53 %>"
SelectCommand="SELECT * FROM [material_issue] ORDER BY [material_issueno] DESC"
Updatecommand="update [material_issue] set [materialissue_date]=@materialissue_date,[qty]=@qty,[sno_to]=@sno_to,[sno_from]=@sno_from
[issue_to]=@issue_to,[issue_by]=@issue_by,[clientname]=@clientname,[entered_by]=@entered_by,[ptypename]=@ptypename,[invoice]=@invoice
[remarks]=@remarks where [material_issueno]=@material_issueno">
</asp:SqlDataSource>
and Error is
Line 2: Incorrect syntax near 'issue_to'.
plese tell me where is the problem
|
|
|
|
|
Aren't you missing a comma after @sno_from ?
prateekfgiet wrote: ,[sno_from]=@sno_from
[issue_to]=@issue_to,[issue_by]=@issue_by,
Scott
|
|
|
|
|
ok thanks
now its working
|
|
|
|
|
Server.MapPath("../Admin/Files/" + @"\" + ClientDet.SelectedValue +
@"\" + CurrYear + @"\" + month);
//how to give the above line path for
File_Attach.PostedFile.SaveAs(Server1Url);
Thanks in Advance...
Sorry for asking again and again
|
|
|
|
|
Odds are pretty good you've pissed people off enough that you'll never get it answered.
Jon
Smith & Wesson: The original point and click interface
Both democrats and republicans are playing for the same team and it's not us. - Chris Austin
|
|
|
|
|
Maite, there are many other good things to do than programming.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|