When I select on a radiobutton with AutPostBack true, google recaptcha goes - asp.net

When I select on a radiobutton with AutPostBack true, google recaptcha goes. how can i solve this?
radiobutton with autopostback="true" attr. like this;
<asp:RadioButtonList runat="server" ID="kvkk" CssClass="radioButton" OnSelectedIndexChanged="kvkkSelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Value="0">Kabul Ediyorum</asp:ListItem>
<asp:ListItem Value="1">Kabul Etmiyorum</asp:ListItem>
</asp:RadioButtonList>
div for reCAPTCHA;
<div class="captcha">
<div class="g-recaptcha" data-sitekey="***************************"></div>
</div>
When i select on a item from radiobutton, reCAPTCHA is going.

Try placing the Radio button in a update panel.
so, drag in the script manager, and then say this:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:RadioButtonList runat="server" ID="kvkk" CssClass="radioButton" OnSelectedIndexChanged="kvkkSelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Value="0">Kabul Ediyorum</asp:ListItem>
<asp:ListItem Value="1">Kabul Etmiyorum</asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
So, give the above a try. This does fire what we call a "partial" post-back, and your page load event will fire. And if you have any setup code, or loading of data or controls in the page load event, then make sure you test for first page postback like this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
' my setup and loading of controls data goes here
End If
End Sub

Related

populate textbox from dropdown list value - asp.net with vb.net

I am trying to get an "onchange" (not sure still new to asp) event to enter the select value text into a text box . I can seem to call the function.
here is my code:
<asp:DropDownList ID="ownerdpdnlst" runat="server" ontextChanged="execvalchanged" >
<asp:ListItem Value="(Choose One)">Choose one...</asp:ListItem>
<asp:ListItem Value="name1">name1</asp:ListItem>
<asp:ListItem Value="name2">name2</asp:ListItem>
<asp:ListItem Value="name3">name3</asp:ListItem>
<asp:ListItem Value="name4">name4</asp:ListItem>
<asp:ListItem Value="name5">name5</asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
here is my vb.net code
<script runat=server>
Public Sub execvalchanged(Sender As Object, e As EventArgs) Handles ownerdpdnlst.SelectedIndexChanged
executortxtbx.Text = ownerdpdnlst.SelectedValue
MsgBox(ownerdpdnlst.SelectedValue)
End Sub
</SCRIPT>
any ideas?
In aspx You define OnTextChanged but in code behind SelectedIndexChanged. In aspx, Instead ontextChanged="execvalchanged" use OnSelectedIndexChanged="execvalchanged"– nelekSep 12 at 6:32

Losing update panel trigger from databound gridview in tab container

I'm having some trouble getting a command link in a gridview to maintain it's ability to change tabs after the initial postback. So below you will see the structure of my content (heavily simplified):
<ajaxToolkit:TabContainer runat="server" ID="tabBody">
<ajaxToolkit:TabPanel runat="server" ID="tabPanel1">
<ContentTemplate>
<asp:UpdatePanel runat="server" ID="updPanel1">
<ContentTemplate>
<asp:Gridview runat="server" ID="grd1" OnRowCommand="grd1_RowCommand" OnRowDataBound="grd1_RowDataBound">
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkChangePanels" runat="server" CommandArgument='<%#Eval("id") %>' CommandName="gotopanel2" Text='<%#Eval("FirstName") & " " & Eval("LastName")%>' />
</ItemTemplate>
</asp:TemplateField>
</asp:Gridview>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel runat="server" ID="tabPanel2">
<ContentTemplate>
<asp:UpdatePanel runat="server" ID="updPanel2">
<ContentTemplate>
<asp:Gridview runat="server" ID="grd2">
</asp:Gridview>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
In order to fill the gridview on panel 1, there is a search box which the user types into and I call a function to bind a linq query to it.
Now I add the rowcommand as a postback trigger on rowdatabound:
Protected Sub grd1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lb As LinkButton = CType(e.Row.FindControl("lnkChangePanels"), LinkButton)
If Not lb Is Nothing Then
ToolkitScriptManager1.RegisterPostBackControl(lb)
End If
End If
End Sub
Then here is the code I have to trigger the tab panel to change (and do some other stuff):
Protected Sub grd1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grd1.RowCommand
Dim id = e.CommandArgument.ToString()
Select Case e.CommandName
Case "gotopanel2"
eventDetails(id, "C")
tabBody.ActiveTab = tabPanel2
End Select
End Sub
This causes a proper postback and changes the tab, everything works as intended. But if I go back to the first tab and try clicking another row in gridview 1, nothing happens.
Is there a way to structure this so the that either the tab can change without losing the postback trigger or am I going about this all wrong?
Thanks.
Postback trigger is not lost. Problem is caused by individual UpdatePanels in each tab.
Put entire TabContainer within UpdatePanel and you can remove UpdatePanels from tabs (but you don't have to). Make sure that UpdateMode of that new panel is set to "Always".
I think the reason why it does not change in your example is that UpdatePanel only refreshes it's own content and attribute that decides if tab is visible or not is set for div (tabPanel) outside that UpdatePanel. When you go back to tab with grid you do it client-side by clicking on it and that's when it goes wrong.
To get to the bottom of the problem and figure out why it does work during the first postback you would probably have to debug ajax toolkit javascript for TabContainer control.

Can't find a control in repeateritem.findcontrol

I have a nested repeaters in a form and bind them to tables in a dataset. I can find the controls by name and read and set values in the Itemdatabound event, However I can't find the control by the same name in a button click event. I can find the repeater and the item.
<asp:Repeater ID="rptrDivision" OnItemDataBound="rptrDivision_ItemDataBound" runat="server">
<itemtemplate>
<div class="fluid">
<div class="widget grid12">
<div class="whead"><div class="grid2"><h4 class="fieldDivision" >
<h4 class="fieldDivision" ><asp:Label ID="lblDivName" runat="server" Visible="True" ><%# DataBinder.Eval(Container.DataItem, "LocationName")%></asp:Label></h4></div>
<div class="grid10">
<div class="grid4 divAdmin" ><label><strong>Division Administrator: </strong> </label></div>
<div class="grid8 on_off">
<div class="floatL ml10"><asp:CheckBox ID="cbxDivMgr" name="chbox" runat="server" /></div>
</div>
</div></div>
<asp:Repeater ID="rptrCamera" OnItemDataBound="rptrCamera_ItemDataBound" runat="server" datasource='<%# Container.DataItem.Row.GetChildRows("CameraJoin")%>'>
<HeaderTemplate>
<div class="body">
</HeaderTemplate>
<itemtemplate>
<div class="formRow">
<div class="grid2">
<asp:Label ID="CameraName" runat="server" ><strong><%# Container.DataItem("Name")%></strong></asp:Label> </div>
<div class="grid10" >
<asp:RadioButtonList ID="rblRoles" runat="server" CssClass="mr10" RepeatColumns="5" CellPadding="2" CellSpacing="2">
<asp:ListItem Value="role1" >Role1</asp:ListItem>
<asp:ListItem Value="role2">Role2 </asp:ListItem>
<asp:ListItem Value="role3" >Role3 </asp:ListItem>
<asp:ListItem Value="Role4">role4 </asp:ListItem>
<asp:ListItem Value="none" Selected="True">N/A </asp:ListItem>
</asp:RadioButtonList>
</div>
</div>
</itemtemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
</itemtemplate>
</asp:Repeater>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="buttonM bBlue" OnClientClick="btnSubmit_Click" /> <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="buttonM bBlue" OnClientClick="btnCancel_Click"/>
The submit button is outside the repeater but in the same form
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
For Each Item As RepeaterItem In rptrDivision.Items
If (Item.ItemType = ListItemType.Item) Or (Item.ItemType = ListItemType.AlternatingItem) Then
DivLabel = CType(Item.FindControl("lblDivName"), Label)
DivName = DivLabel.Text
DivMgr = CType(Item.FindControl("cbxDivMgr"), CheckBox)
'''do some logic
End If
Next
End Sub
I've looked in the debugger and item has the correct number of controls so I know I am in the right place, but the findcontrol in the repeater item can't locate the control by name. It always comes back as null.
Every example I can find from here to MSDN forums to asp.net to bytes.com show looping through the items in the repeater and calling the find control the same way. I can't figure out what I am doing wrong.
Edit:
SO here is the kicker just make sure I'm not crazy I did a loop through the controlscollection on the repeater item and on the second control it comes back with the ID "lblDivName" yet if I call the item.findControl("lblDivName") it returns a null value.
Control events (like a Button's click event) occur before DataBound events (see ASP.NET Page Life Cycle on MSDN for more information). Thus, your Repeater is not DataBound yet, so its databound controls have not been initialized (they are null).
You have some options.
Preferably, you would use the Repeater's databound event to work with it's data items - since this is when you know for sure that they are initialized and populated with values.
However, you could just call "DataBind" prior to doing the processing in your Click event:
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
rptrDivision.DataSource = yourDataSource
rptrDivision.DataBind()
For Each Item As RepeaterItem In rptrDivision.Items
' The rest of your code
End Sub
This should ensure that your controls have values.

How to customize calendar selection in ASP.NET

i'm trying to come up with a DateTime Picker in ASP.Net using textBox, Calendar, Button and Updatefields.
if a user clicks a button the panel with a hidden calendar will become visible, and if a user selects a date calendar's visibility will become false and he date will be assigned to textBox.
My problem comes if a user wants to change month because in this case calendar will disappear because selectionChange is being triggered.
My question is how can I fish out the changing of the month and bound the hiding of the panel only if a date is selected?
thank you very much in advance.
here are the code samples:
front part:
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox2" runat="server" />
<asp:ImageButton ID="Imbut" runat="server" ImageUrl="imagesNew/calender.png" Height="17px" Width="17px" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Calendar1" EventName="SelectionChanged" />
</Triggers>
</asp:UpdatePanel>
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server">
<asp:Calendar ID="Calendar1" runat="server" Height="129px" Width="209px">
</asp:Calendar>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Imbut" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
back part
Protected Sub Imbut_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Imbut.Click
Panel1.Visible = True
End Sub
Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Calendar1.SelectionChanged
TextBox2.Text = Calendar1.SelectedDate.ToString("dd/MM/yyyy")
Panel1.Visible = False
End Sub
I struggled with a similar problem. The problem is (as you stated) on the postback the control gets reset. I never found a means to do this elegantly with asp.net controls. I was able to accomplish this using the jQuery calendar and asp:hidden field. Keeping it client side via javascript I was able to allow the user to navigate the calendar change dates etc. When a date was selected the values were set to both a textbox within the ui as well as a hidden field then on submission, the value within the textbox or hidden field was picked up server side and used (in my situation) as a filter parameter.

Show loading message on SelectedIndexChanged event of drop down list

I'm trying to show message "Loading..." when a user select an item in the dorp down list.
Mark up:
<asp:Label ID="lbl_LoadingMessage" runat="server" ></asp:Label>
<asp:DropDownList ID="ddl_Chapter" runat="server" AutoPostBack="True">
</asp:DropDownList>
Code behind:
Protected Sub LoadMessage()
lblLoading.Text = "Loading..."
End Sub
Protected Sub ddl_Chapter_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_Chapter.SelectedIndexChanged
LoadMessage()
Dim redirectURL As String = "~/chapter.aspx?bid=" & BookId.ToString
Server.Transfer(redirectURL)
End Sub
The method I'm using above is not working. When I select a new item from the drop down list, it works as expected except the message "Loading..." is not showing at all. Any suggestion or code sample? Thank you.
You will have to do this on the client side using javascript.
At the moment, your dropdown menu is causing a postback. when the drop down menu is changed, the page post backs then the entire page life cycle is run through. When the event ddl_Chapter_SelectedIndexChanged is run, you set the text of the loading label, but you never reload the page (which would have your loading message) - instead you server.transfer to a new page.
If you use jQuery, you could set the labels text value as soon as the dropdown is changed
something like:
$('#the_full_renedered_ID_of_ddl_Chapter').change(function () {
$('#the_full_renedered_ID_of_lbl_LoadingMessage').html("Loading...")
});
Or use javascript:
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" /></script>
<script type="text/javascript">
$(document).ready( function() {
$("#<%= ddl_Chapter.ClientID %>").change(function()
{
window.alert("Loading");
});
});
</script>
The whole event will execute before the page re-rendering will take place.
If you are going to be doing extra processing between the LoadMessage() and the Server.Transfer try using AJAX UpdateProgress panel and adding your "loading..." message to that and add your dropDownList to a UpdatePanel.
This way depending on what code needs executing in your SelectedIndexChanged event it will show the "loading..." message before it via a partial page postback.
e.g
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress id="UpdateProgress1" runat="server" associatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<p>Loading....</p>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel id="UpdatePanel1" runat="server" childrenAsTriggers="true">
<ContentTemplate>
<asp:DropDownList id="DropDownList1" runat="server" autoPostBack="true">
<asp:ListItem selected="True" value="1">Book 1</asp:ListItem>
<asp:ListItem value="2">Book 2</asp:ListItem>
<asp:ListItem value="3">Book 3</asp:ListItem>
<asp:ListItem value="4">Book 4</asp:ListItem>
<asp:ListItem value="5">Book 5</asp:ListItem>
</asp:DropDownList>
<asp:Label id="lblSelected" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
This way the "loading..." message will be displayed for the duration of the processing of what you are trying to achieve in your SelectedIndexChanged event. If this is simply for display reasons javaScript would be your best bet.

Resources