I am integrating a Captcha control inside a CreateUserWizard.
I got the Captcha control sample code from this website here
As I wanted to do a validation for user's input based on the Captcha using an if.. else.. statement.
However an error occured when I trying to get the Captcha control from the createuserwizard.
Here the is error :
The name 'Captcha1' does not exist in the current context
I had tried to get this control as a textbox, image, control but it was not successful.
Here is the code :
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<tr>
<td class="style4">Answer:</td>
<td>
<cc1:CaptchaControl ID="Captcha1" runat="server"
CaptchaBackgroundNoise="Medium" CaptchaLength="5"
CaptchaHeight="55" CaptchaWidth="200"
CaptchaLineNoise="None" CaptchaMinTimeout="5"
CaptchaMaxTimeout="240" FontColor = "#FF33CC" CaptchaFontWarping="Medium" />
<asp:TextBox runat="server" ID="txtCaptcha" />
</td>
</tr>
</ContentTemplate>
</asp:CreateUserWizardStep>
Behind code:
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
//Control Captcha1 = (Control)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Captcha1");
TextBox txtCaptcha = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtCaptcha");
Captcha1.ValidateCaptcha(txtCaptcha.Text.Trim());//error occurred here
if (Captcha1.UserValidated)//error occurred here
{
}
}
Try this to find the Controls inside the CreateUserWizard
TextBox txtCaptcha = (TextBox)CreateUserWizardStep1.CreateUserStep.ContentTemplateContainer.FindControl("txtCaptcha");
Related
I need help with Umbraco user control.
I create a user control to get input from user.
ascx file
<form id="formRegister" runat="server">
<table>
<tr>
<td>
<asp:TextBox ID="txtUserName" type="text" placeHolder="User Name" runat="server" ClientIDMode="Static"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" ClientIDMode="Static" Text="Submit" OnClick="btnSubmit_Click" />
</td>
</tr>
</table>
the ascx.cs file
protected void Page_Load(object sender, EventArgs e)
{
var b = 0;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
var a = 0;
}
but somehow when it's loaded i get this in firebug
<form id="formRegister" action="/register/" method="post">
So the form create it's own action and do that action when I click the submit button instead of the btnSubmit_click event.
What should I do?
User controls won't fire their on click events when loaded as a macro in an Umbraco MVC site. Create a partial view and surface controller instead.
<asp:Button ID="btnCheckPatientID" CssClass="cssbutton" runat="server" Text="Check"
OnClick="btnCheckPatientID_Click" />
<asp:ModalPopupExtender ID="btnCheckPatientID_ModalPopupExtender" runat="server"
PopupControlID="panelCheckPatient" TargetControlID="hiddenTargetControlForModalPopup"
BackgroundCssClass="modalbackground" CancelControlID="btnClose">
</asp:ModalPopupExtender>
<asp:Button runat="server" ID="hiddenTargetControlForModalPopup" Style="display: none" />
<div id="panelCheckPatient" class="modalpopup" style="display: none">
<iframe id="iframeCheckPatient" class="csstable" runat="server" width="550px" height="485px" scrolling="auto">
</iframe>
<table>
<tr>
<td align="right">
<asp:Button ID="btnClose" runat="server" CssClass="cssbutton" Text="Close" />
</td>
</tr>
</table>
</div>
Serve Code
protected void btnCheckPatientID_Click(object sender, EventArgs e)
{
iframeCheckPatient.Attributes["src"] = "Check_Patient.aspx?patientID=" + txtPatientID.Text.Trim();
btnCheckPatientID_ModalPopupExtender.Show();
}
I have open an Ajax Modal popup on click of btnCheckPatientID.
In Modal Popup load an iframe which contains Check_Patient.aspx page.All working correctly.
In Check_Patient.aspx there is Pass button.
On click of button i have to return some value to parent page.
What should i do.
Search on google but cant find any help
You can use button postbackurl property where you need to specify your parent page address and on the parent page use the following code:
let say you have a textbox on your popup, you can use the same as folows
TextBox txtnew=(TextBox)PreviousPage.FindControl("id or name of control");
and then use its value OR create a property on popup page like
public string popupdata
{
get; set;
}
popupdata=your poppage value;
now access the same on parent page using
string str=PreviousPage.popupData.Tostring();
OR you can use cookies or session as your other options.
I'm developing a ASP.NET website with a C# backend. I'm having a problem with how to set an onclick event for buttons that are nested inside of both a loginview and a repeater. The code works fine for displaying all of the other data (anonymous view displays only an error message) but right now the buttons just redirect to the same page and remove the repeater and all contents, whereas they're supposed to run a specific delete function. The repeater, as it is right now, uses an alternatingitem template. If I remove the buttons from the nested controls, they work. I've tried this with buttons, linkbuttons, and imagebuttons. I'd rather use the latter, if possible. Is it possible to assign an Onclick to these buttons if they're nested like this? If not, what approach should I use?
<asp:LoginView ID="LoginLinksView" runat="server" EnableViewState="false">
<AnonymousTemplate>
<asp:Label ID="errorlabel" runat="server"></asp:Label>
</AnonymousTemplate>
<LoggedInTemplate>
<asp:Repeater id="Repeater" runat="server" >
<HeaderTemplate>
<table cellspacing="0" cellpadding="0">
<thead></thead>
</HeaderTemplate>
<ItemTemplate>
<tr class="Repeaterrow">
<!--Additional code here-->
<asp:ImageButton ID="delbutton" runat="server" ImageUrl=
"~/Images/delete.png" Onclick="DeleteOnClick"/>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="Repeaterrow">
<!--Additional code here-->
<asp:ImageButton ID="delbutton" runat="server" ImageUrl=
"~/Images/delete.png" Onclick="DeleteOnClick"/>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</LoggedInTemplate>
</asp:LoginView>
Here are the problems with your approach
1- The button issues postback as it should. But you need to put some CommandArgument with to identify "key" or which row you are processing it for.
2- Re Bind your Repeater with source. Below is the sample code for you.
protected void Page_Load(object sender, EventArgs e)
{
BindRepeater();
}
private void BindRepeater()
{
List<int> items = new List<int>();
for (int i = 0; i < 10; i++)
{
items.Add(i);
}
Repeater.DataSource = items;
Repeater.DataBind();
}
protected void DeleteOnClick(object sender, EventArgs e)
{
ImageButton delbutton = (sender as ImageButton);
//1- call your method with passing in delbutton.CommandArgument - it will give you key/ whatever you like
//2- Rebind the Repeater here and that will bind controls again...
BindRepeater();
}
protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
ImageButton delbutton = (sender as RepeaterItem).FindControl("delbutton") as ImageButton;
if (delbutton != null)
{
delbutton.CommandArgument = (sender as RepeaterItem).ItemIndex.ToString();
}
}
and ASPX Repeater definition would change to
Thanks,
Riz
I've got this code in the code-behind on my page, which works perfectly fine for a repeater:
protected void AcctAssnRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PBRConnectionString"].ConnectionString);
con.Open();
{
string str10 = ((HtmlInputText)e.Item.FindControl("txtFlgUpdatedOn")).Value;
}
}
I'm trying to do something similar on another page, but it is telling me that "item" isn't valid:
protected void btnSubmit_OnClick(object sender, EventArgs e)
{
string str10 = ((HtmlInputText)e.Item.FindControl("txtDtSentToCIS")).Value;
}
I'm still a C# n00b, can anyone tell me how to reference the value inside this control? Both pages have a runat="server" on the aspx side, so I would expect that there's a way to do it, I'm sure my syntax just needs adjusting.
Thanks!
EDIT: Here's a piece of the aspx. Maybe I should note that it's all inside a Tab Control.
<div style="width:430px;border:1px solid blue;float:left;">
<asp:Panel ID="Panel3" runat="server" Height="220px" style="float:left; margin-left: 19px"
Width="410px">
<table>
<tr>
<td width="210px">BIL Name:</td>
<td width="200px"><asp:textbox id="txtCISName" runat="server"></asp:textbox></td>
</tr>
<tr>
<td width="210px">Date Sent To BIL:</td>
<td width="200px"><input type="text" id="txtDtSentToCIS" class="datepicker" name="txtDtSentToCIS" runat="server" style="height: 14px; width: 70px" /></td>
</tr>
<tr>
<td width="210px">BIL Sign Off Received:</td>
<td width="200px"><asp:DropDownList ID="cboCISSignOff" runat="server" Height="16px"
AutoPostBack="True" onselectedindexchanged="chkCISSignOff_CheckedChanged">
<asp:ListItem>N</asp:ListItem>
<asp:ListItem>Y</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td width="210px"><asp:Label runat="server" Text="BIL Response:" ID="CISResp" /></td>
<td width="200px"><asp:textbox id="txtCISResponse" runat="server"
textmode="MultiLine" rows="9" Width="180px"></asp:textbox></td>
</tr>
</table>
</asp:Panel>
</div>
You should be able to use the ID to reach the control. For ex. a textbox:
<asp:TextBox ID="txtDtSentToCIS" runat="server" />
In your code behind you can do something as
SomeMethod(this.txtDtSentToCIS.Text);
or
string enteredByUser = this.txtDtSentToCIS.Text;
If you want to access repeater containing textbox(es) from outside the repeater, you may code like this:
Iterating the RepeaterItemCollection:
foreach (RepeaterItem item in Repeater1.Items)
{
TextBox txtDtSentToCIS = item.FindControl("txtDtSentToCIS") as TextBox;
}
Or simply accessing through indexer:
TextBox txtDtSentToCIS = Repeater1.Items[1].FindControl("txtDtSentToCIS") as TextBox;
Good luck.
If you are using asp I would suggest that you use an asp Text box.
<asp:TextBox ID="textBoxName" runat="server" />
When the button is clicked and you OnClick method is called you can search for the text box by name and assign the text to your string.
string str10 = textBoxName.text;
You don't really need to use the find control unless that control is buried in another control like a grid view or login view.
What could be happening is that the FindControl method only works for the first control collection in this case the only control contained is "Panel3", try this:
var panel = e.Item.FindControl("Panel3") as Panel;
string str10 = ((HtmlInputText)panel.FindControl("txtFlgUpdatedOn")).Value;
Good luck
Hi I have created user control for re-sizable text box.
<asp:Panel ID="PanelText" runat="server" CssClass="frameText">
<asp:TextBox runat="server" ID="TextBoxResizable" CssClass="noborder" Width="100%"
Height="100%" TextMode="MultiLine">
</asp:TextBox>
</asp:Panel>
<cc1:ResizableControlExtender ID="ResizableTextBoxExtender" runat="server" TargetControlID="PanelText"
ResizableCssClass="resizingText" HandleCssClass="handleText" OnClientResizing="OnClientResizeText" />
And have created Validator property for this control like:
[ValidationProperty("Text")]
public partial class ResizableTextBoxControl : System.Web.UI.UserControl
{ public string Validator
{
get { return this.TextBoxResizable.Text; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
In aspx page I am using this control like:
<uc1:ResizableTextBoxControl ID="tbDescription" MinimumHeight="50" MinimumWidth="100"
MaximumHeight="300" MaximumWidth="400" runat="server" onKeyPress="javascript:Count(this,1500);" onKeyUp="javascript:Count(this,1500);" ValidationGroup="vgSubmit" ></uc1:ResizableTextBoxControl>
<asp:RequiredFieldValidator ID="rfvDescription" runat="server" controlToValidate="tbDescription" ValidationGroup="vgSubmit" ErrorMessage="Description" Text="*" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
When I click on submit, "tbDescription" does not appear to be mandatory.
What can be wrong with the code?
EDIT
Ok...I got what was the problem, one control was hidden, and required field validator for that control was not disabled, I did it using jquery and now everything is fine except asterics.. I dont understand why asterics are not visible..
try placing your validator to your controlle especially if you just try to validate one textbox
<asp:Panel ID="PanelText" runat="server" CssClass="frameText">
<asp:TextBox runat="server" ID="TextBoxResizable" CssClass="noborder" Width="100%"
Height="100%" TextMode="MultiLine">
</asp:TextBox>
<asp:RequiredFieldValidator
ID="rfvDescription" runat="server" controlToValidate="TextBoxResizable"
ValidationGroup="vgSubmit"
ErrorMessage="Description" Text="*"
ForeColor="Red" SetFocusOnError="True">
</asp:RequiredFieldValidator
</asp:Panel>
<cc1:ResizableControlExtender ID="ResizableTextBoxExtender"
runat="server" TargetControlID="PanelText"
ResizableCssClass="resizingText" HandleCssClass="handleText OnClientResizing="OnClientResizeText" />
in to the user controller it might not be recognized after the page is rendered.
try using Page.IsValid in your Submit button event.
if (!Page.IsValid) {
return;
}
Sorry for all the trouble,
There was one control on page which was hidden and required field validator for that control was not disabled. I disabled it using jQuery like
$(document).ready(function () {
if (!$("#<%=TextBoxResizable.ClientID %>").is(":visible")) {
ValidatorEnable(<%=rfvTextBoxResizable.ClientID %>, false);
}
})
Asteric is visible after placing required field validator outside Panel.