I have 2 radio buttons on a simple web page and If I click one of them the other should be false(i.e checked=false) but it's not working Can anyone point me the mistake I'm doing.I knew it's a silly one but I need to know what's going on?
Here are the radio buttons:
<asp:RadioButton ID="Rb1" runat="server" Text=""/>
<asp:RadioButton ID="Rb2" runat="server" Text=""/>
Onchecked changed event:
Protected Sub Rb1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Rb1.CheckedChanged
Rb2.Checked = False
End Sub
Protected Sub Rb2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Rb2.CheckedChanged
Rb1.Checked = False
End Sub
You have to set GroupName property and AutoPostBack=True.
Related
I have a very simple Textbox and Button, but Button click event not firing at first time ( only firing in second click)
<asp:TextBox ID="TxtSurvey" runat="server"></asp:TextBox> <br />
<asp:Button ID="BtnGoSurvey" runat="server" Text="LetsGo"/>
The code is very simple too
Protected Sub BtnGoSurvey_Click(sender As Object, e As EventArgs) Handles BtnGoSurvey.Click
Session("IDSurvey") = TxtSurvey.Text
BtnGoSurvey.PostBackUrl = "~/Survey.aspx"
End Sub
What i'm doing wrong ?
Thanks for help
If you can use Response.Redirect, then following is supposed to work:
Protected Sub BtnGoSurvey_Click(sender As Object, e As EventArgs) Handles BtnGoSurvey.Click
Session("IDSurvey") = TxtSurvey.Text
Response.Redirect("~/Survey.aspx",True)
End Sub
I've placed some controls in a panels. When the page postback, I'm trying to retrieve the posted values, but only the older value seems to be there.
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim _txtFName As TextBox = FindControl("editNamePanel").FindControl("txtFName")
Dim _txtMName As TextBox = FindControl("editNamePanel").FindControl("txtMName")
Dim _txtLName As TextBox = FindControl("editNamePanel").FindControl("txtLName")
End Sub
Even when I hover over the e EventArgs is null. Am I missing something?
EDIT
I'm getting new values when I put the above code in the page load event handler
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Page.IsPostBack Then
'The above code here ...
End If
End Sub
Thank for helping
In your aspx
<asp:Panel ID="editNamePanel" runat="server">
<asp:TextBox ID="txtFName" runat="server"></asp:TextBox>
<asp:TextBox ID="txtMName" runat="server"></asp:TextBox>
<asp:TextBox ID="txtLName" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</asp:Panel>
In your code behind
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim _txtFName As TextBox = txtFName
Dim _txtMName As TextBox = txtMName
Dim _txtLName As TextBox = txtLName
End Sub
I have a total of 4 views. in view 1 the user inputs their first name then clicks a button to go into the next view
<lable for="fname">First Name</lable>
<asp:TextBox ID="fname" runat="server" required></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" style="color:red" ErrorMessage="* Letters Only" ControlToValidate="fname" ValidationExpression="^[aA-zZ]*$" ></asp:RegularExpressionValidator>
i want to re-display the user's input on the 3rd view. this is my code for it
<asp:Label ID="cardName" runat="server" Text="Name On Card"></asp:Label>
<asp:Label ID="Label1" runat="server" ></asp:Label>
vb for it
Private Sub View3_Activate(sender As Object, e As EventArgs) Handles View3.Activate
Label1.Text = fname.Text
End Sub
this does not work, so i tried this
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Label1.Text = fname.Text
End Sub
(when button three is clicked, the page goes to view 3 from view 2. button type is not submit)
None of this has worked for me
You can use ASP.NET Session to store the value the user entered and then pull that value out of Session when you want to display it on view 3.
In button click event handler on view 1, do this:
Protected Sub View1_ButtonClick(sender As Object, e As EventArgs) Handles Button1.Click
Session("FirstName") = fname.Text
End Sub
Now in the Page_Load of view 3, do this:
Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
' Get first name value out of Session by name here and set label
Label1.Text = Session("FirstName").ToString()
End Sub
Note - Things you put into Session are of type Object so you must cast the value to the correct type. In this case, the .ToString() makes it a String that can be put as the text of the label.
On my web form I have a TextBox which I want to perform custom validation on:
<asp:TextBox ID="tbDate" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
<asp:CustomValidator runat="server" ID="valDate" ControlToValidate="tbDate" onServerValidate="valDate_ServerValidate" ValidateEmptyText="true" ></asp:CustomValidator>
In my code behind, I set the date TextBox's Text in Page_Load, and I have a validation function:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
tbDate.Text = DateTime.Today.ToShortDateString
End Sub
Protected Sub valDate_ServerValidate(source As Object, args As ServerValidateEventArgs)
Dim newDate As DateTime
args.IsValid = DateTime.TryParse(args.Value, newDate)
End Sub
Here's the problem: If I enter a value in the textbox and click the submit button (or hit Enter), the validation function doesn't receive the value that I typed. Instead, inside valDate_ServerValidate, args.Value is set to the textbox's initial value that was set in Page_Load. What's going on here?
You are always overwriting the value, so change
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
tbDate.Text = DateTime.Today.ToShortDateString
End Sub
to
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then tbDate.Text = DateTime.Today.ToShortDateString
End Sub
I am using label control in form designing.But i want to hide that particular label control on page load.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label10.Visible = False
End Sub
What should i do? I'm new to vb.net.
Try setting the visibility property within the aspx code rather than within the load event, this may solve your issue.
<asp:Label ID="lblValidation" runat="server" BackColor="Red"
Text="Please fill in all of the date fields below to proceed" Visible="False"></asp:Label>
Hope this helps!