I'm making a captcha for my site, nothing fancy and for personal use. My problem is that when i hit the refresh button to bring up a new image in the captcha box it should reset the captcha text box as well.
I am setting it like so
protected void btnRefresh_Click(object sender, EventArgs e)
{
//This is the call that creates a new image
FillCaptcha();
// to clear the text box
txtCaptcha.Text = String.Empty;
}
When i run the debugger it shows the values entered in the text box and after when its set to "".
Here is the button and text box layout
<asp:TableRow>
<asp:TableCell>
Enter Below Captcha Code :
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtCaptcha" runat="server" Width="200px"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
</asp:TableCell>
<asp:TableCell VerticalAlign="middle">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UP1" runat="server">
<ContentTemplate>
<table>
<tr>
<td style="height: 50px; width:120px; border:solid; border-color:blue; text-align:center;">
<asp:Image ID="imgCaptcha" runat="server" />
</td>
<td valign="middle">
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:TableCell>
</asp:TableRow> `
Ive search on Stack for some time and everyone seems to be setting it as i have it. I have the same call to the txtCaptcha.Text = String.Empty; in another function and it works fine. any help would be grateful. If I'm unclear about something let me know and ill do my best to better explain it.
Captcha layout
You should move your TextBox inside UpdatePanel. Like So:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UP1" runat="server">
<ContentTemplate>
<table>
<tr>
<td colspan="2">
<asp:TextBox ID="txtCaptcha" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="height: 50px; width:120px; border:solid; border-color:blue; text-align:center;">
<asp:Image ID="imgCaptcha" runat="server" />
</td>
<td valign="middle">
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
Read about Introduction to the UpdatePanel Control
Related
I have registration form for users to fill up. In there, one field is there to which if user checks on the button a text box shoulld be enabled to enter the number. I have used following code :
<asp:UpdatePanel ID="upMSME" runat="server">
<ContentTemplate>
<tr>
<td colspan="2">
<asp:Label ID="lblMSME" runat="server" Text="Whether covered under MSME (Tick whichever is applicable)"></asp:Label>
<asp:CheckBox AutoPostBack="true" Checked="true" ID="chbMSME" runat="server" OnCheckedChanged="chbMSME_CheckedChanged" ClientIDMode="AutoID"/>
</td>
</tr>
<tr id="trMSMENo" runat="server">
<td>
<asp:Label ID="lblMSMENo" runat="server" Text="MSME Number" CssClass="alignTop"></asp:Label>
</td>
<td class="ValueBox">
<asp:TextBox ID="txtMSMENo" runat="server" MaxLength="75"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvMSMENo" runat="server" ForeColor="Red" ErrorMessage="*" ControlToValidate="txtMSMENo" ValidationGroup="vgVendor"></asp:RequiredFieldValidator>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
However I searched over internet and found that by setting the ClientIDMode="AutoID" the issue is resolved. But in my case after setting the property there is still full postback occurred.
I have another update panel also in this form, does it make any difference?
What am I missing?
I hope you are coding well,
I am working on a Image Upload module , which is in a Modal Popup and hence is wrapped inside an Update Panel,
<asp:UpdatePanel runat="server" ID="UpdateModelPopup" UpdateMode="Conditional" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnkUploadImage" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Panel runat="server" ID="pnlModel" CssClass="ModalWindow">
<!-- Style="display: none;" -->
<table border="0" class="modalTable" cellspacing="5">
<tr>
<td>
Keywords 2<strong><font color="#FF0000">*</font></strong> <i>(Seperated by , )</i>
<br />
<asp:TextBox runat="server" ID="txtKeywordsTwo"></asp:TextBox><br />
</td>
<td>
Dimensions <strong><font color="#FF0000">*</font></strong>
<br />
Width :
<asp:TextBox ID="txtDimWidth" runat="server" Width="50px"></asp:TextBox>
Height :
<asp:TextBox ID="txtDimHeight" runat="server" Width="50px"></asp:TextBox>
</td>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>
Browse .psd file<br />
<ajaxToolkit:AsyncFileUpload runat="server" ID="pdfFile" Width="200px" OnUploadedComplete="pdfFile_UploadedComplete"
CompleteBackColor="" ErrorBackColor="" OnClientUploadComplete="Success" />
<asp:Image runat="server" ID="imgThumbNail" /><br />
<font color="#FF0000">or</font><br />
Refrence URL<br />
<asp:TextBox ID="TextBox11" runat="server"></asp:TextBox>
</td>
<td>
Browse file <i>(.jpeg, .gif or .png)</i><strong><font color="#FF0000">*</font></strong><br />
<ajaxToolkit:AsyncFileUpload runat="server" ID="AsyncFileUpload1" Width="200px" />
</td>
</tr>
</table>
<asp:Button runat="server" ID="btnUpload" Text="Upload" CssClass="btn" OnClick="btnUpload_Click" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Now as per the business requirement, I need to show a thumbnail of the Image that user uploads, and for .psd file I have a standard icon which I display's at the run time, in the code behind I am validating the file extension to be the .psd file and it is then display the psd icon, I am trying to set the ImageURL for
protected void pdfFile_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if (Path.GetExtension(e.FileName).ToString().ToLower() != ".psd")
{
string alertMsg = #"alert('Please provide .PSD type file');";
ScriptManager.RegisterStartupScript(this, this.GetType(), "Test", alertMsg, true);
//pdfFile
}
else
{
imgThumbNail.ImageUrl ="~/images/psdIcon.jpg";
}
}
The problem is that Panel doesnt gets update at the run time, even the page source shows src="". I am suspecting that its a Update Panel issue.
Kindly point me into the right direction.
Thanks in advance
FileUpload can not be done Asynchronously. In order to do that PostBackTrigger Trigger will be required to upload.
I have a drop-down list which gathers data from the database and a textbox which contains the text from the drop-down list when I select a value from the drop-down list. I tried to make this work, but no data appears in the textbox when I select a value from the drop-down list and no errors appear either. Can anyone help me?
aspx Code:
<table id="Tbl" runat="server" width="70%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td>
Select
</td>
<td>
<asp:SqlDataSource ID="SDSOption" runat="server" ConnectionString="Data Source=ELARABY-1EACFA3\SQLEXPRESS;Initial Catalog=ElarabyGroup;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [Id], [option] FROM [Option]">
</asp:SqlDataSource>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SDSOption" DataTextField="option"
DataValueField="Id" ondatabound="DropDownList1_DataBound"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
<td>
<b style="font-style: italic">Select Option</b> <b style="font-style: italic">
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TxtOption"
Display="Dynamic" ErrorMessage="*" SetFocusOnError="True"><b style="font-style: italic">*</b></asp:RequiredFieldValidator>
</b>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="LblOption" runat="server" Text="Option"></asp:Label>
</td>
<td class="style1">
<asp:TextBox ID="TxtOption" runat="server"></asp:TextBox>
</td>
<td>
<b style="font-style: italic">Note:Add Here Product Option</b> <b style="font-style: italic">
<br />
<asp:RequiredFieldValidator ID="RVOption" runat="server" ControlToValidate="TxtOption"
Display="Dynamic" ErrorMessage="*" SetFocusOnError="True"><b style="font-style: italic">*</b></asp:RequiredFieldValidator>
</b>
</td>
</tr>
<tr style="font-style: italic">
<td class="style2">
</td>
<td>
<asp:Button ID="BtnSubmit" runat="server" Height="20px" Text="Submit" Width="50px"
OnClick="BtnSubmit_Click" />
</td>
<td align="left">
<b><i><span><a href="EditOption.aspx">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Backend/Image/www_4photos_net_1137678404.jpg"
Width="60px" /></a> Display Other </span></i></b>
</td>
</tr>
</table>
CS Code:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TxtOption.Text += DropDownList1.SelectedItem.Value;
}
The DropDownList is wrapped in an UpdatePanel, but the TextBox is not.
What this means is during the asychronous postback (triggered on the SelectedIndexChanged event), the postback only has visiblity of the controls inside the UpdatePanel (as this is all that gets submitted to the server).
Because the TextBox is outside the UpdatePanel, it does not have visibility of it during the async postback.
The easiest solution would be to put the Textbox inside the UpdatePanel.
Another solution would be to use ScriptManager.RegisterStartupScript to set the value of the control from the SelectedIndexChanged event using basic JavaScript (which has access to the entire DOM, unlike the asynchronous postback).
E.g
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(UpdatePanel1,
this.GetType(),
"NameOfScript",
string.Format("document.getElementById('{0}').value = '{1}';",
txtOption.ClientId,
DropDownList1.SelectedValue));
}
I have a fileupload control with an updatePprogress in an updatePanel like this:
UpdatePanel is: updExtraSmall
<Triggers>
<asp:PostBackTrigger ControlID="lnkExtraSmall" />
</Triggers>
<ContentTemplate>
<table>
<tr>
<td style="border: 1px">
<asp:FileUpload ID="fupldExtraSmall" runat="server" />
</td>
<td>
<asp:LinkButton ID="lnkExtraSmall" OnClientClick="javascript:showWait();" OnClick="lnkExtraSmall_click" CausesValidation="false"
runat="server" Text="Upload" />
<asp:Label ID="lblMessage" runat="server" />
</td>
<td>
<asp:Label ID="lblExtraSmallMessage" runat="server" />
</td>
<td>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updExtraSmall">
<ProgressTemplate>
<DIV id="IMGDIV" align="center" valign="middle" runat="server" style="position: absolute;left: 35%;top: 25%;visibility:visible;vertical-align:middle;border-style:inset;border-color:black;background-color:White">
<img src="loading/loading.gif" /><br />
</DIV>
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
</table>
</ContentTemplate>
and:
function showWait()
{
if ($get('fupldExtraSmall').value.length > 0)
{
$get('UpdateProgress1').style.display = 'block';
}
}
The problem is that the updateProgrss doesn't show.
Can anyone help me please?
Thank you,
Alina
Just Use the asyncfileupload control which come with ajaxcontroltoolkit 3.0 and then upload the file.
Put the UpdateProgress outside the ContentTemplate.
Ref: http://msdn.microsoft.com/en-us/library/bb398821.aspx
I have a button which is not working when placed below two panels. If I move it above the panels, it works.
It works either way in Firefox. It does not work in IE 8
The button runs this code
protected void Button2_Click(object sender, EventArgs e)
{
panelForm.Enabled = true; //input panel
panelOutput.Visible = false; //output panel
Button1.Visible = true; //input panel button
}
I have some workarounds, but was hoping to find the cause of the issue.
edit: here is the markup of the second panel and button. I've tried moving the button outside of the panel and get the same result.
<asp:Content ID="MainContent" Runat="Server" ContentPlaceHolderID="MainContentPlaceHolder">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="domainUserID" runat="server" Visible="false"></asp:TextBox>
<!-- gray bar and title -->
<table style="width:100%; border-style:none;">
<tr>
<td class="com_headline">
SQL Emergency Request [Home]
</td>
</tr>
<tr class="com_app_instructions">
<td>
<p>Words here</p>
</td>
</tr>
</table>
<!-- end title and gray bar -->
<asp:Panel ID="panelForm" runat="server" Visible="True" CssClass="myform">
<form method="post" action="Default.aspx" id="form">
<h1>Request Form</h1>
<p>Complete this form to be issued a login</p>
<table cellpadding="5px">
<tr>
<td>
IR Number
<br />
<span class="small">Obtain your IR number from
SMART</span>
</td>
<td>
<asp:TextBox ID="txtIR" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtIR" CssClass="errorMsg"
ErrorMessage="Please Enter Your IR Number">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Server
<br />
<span class="small">MSSQL5 is supported for now</span>
</td>
<td>
<asp:DropDownList ID="ddServer" runat="server" AutoPostBack="True"
Enabled="False" onselectedindexchanged="ddServer_SelectedIndexChanged">
<asp:ListItem>DEVMSSQL05</asp:ListItem>
<asp:ListItem Selected="True">MSSQL05</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="ddServer" CssClass="errorMsg"
ErrorMessage="Please Choose A Server">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Database
<br />
<span class="small">You have the role of 'Analyst' in these databases</span>
</td>
<td>
<asp:DropDownList ID="ddDatabase" runat="server" AppendDataBoundItems="true"
AutoPostBack="false" DataSourceID="DatabaseDropDownObjectDataSource"
DataTextField="DatabaseName" DataValueField="DatabaseName" Width="150">
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="Button1" runat="server" CssClass="com_btn_flat"
onclick="Button1_Click" Text="Submit" />
</td>
<td>
<div id="loader">loading...</div>
</td>
</tr>
</table>
</form>
</asp:Panel>
<asp:Panel ID="PanelError" runat="server" Visible="false" CssClass="errorPanel">
<h1><asp:Label ID="txtErrorMsg" runat="server">error text</asp:Label></h1>
</asp:Panel>
<br />
<asp:Panel ID="panelOutput" runat="server" Visible="false" CssClass="panelOutput">
<h1>
<asp:Literal ID="Title" runat="server" Text=""/>
</h1>
<p>
<asp:Literal ID="Warning" runat="server" Text=""/>
</p>
<p>
<asp:Literal ID="LoginLifeHours" runat="server" Text=""/>
</p>
<p>
<span class="important">
<asp:Literal ID="Login" runat="server" Text="" />
</span>
</p>
<p>
<span class="important">
<asp:Literal ID="PWD" runat="server" Text="" />
</span>
</p>
<br />
<p>
<asp:Button ID="Button2" runat="server" Text="Request Another Login"
onclick="Button2_Click" CssClass="com_btn_flat" />
</p>
</asp:Panel>
This is the button that is not responding in IE
<p>
<asp:Button ID="Button2" runat="server" Text="Request Another Login"
onclick="Button2_Click" CssClass="com_btn_flat" />
</p>
The problem is that you are using a <form> tag within your content page. The master page already includes a <form> tag and IE appears to be balking at the form within a form. When I removed the <form> tag from your aspx, the button handler ran under IE8.
The sample code is Button2_Click, but your button markup outside of the panels has test_button_Click as the event handler? There are three buttons, so which one are you asking about, I assume the last?
I noticed that you have a tag inside your first panel (panelForm). Also, I don't see a a tag with a runat="server" attribute (although, it could be in a master page). And it doesn't look like your button is inside a form (unless the master page has a form).
The problem is that you can only have one form on a page in Asp.NET WebForms. If you don't have any <form runat="server"> tags on your page, then you buttons will not fire any events on the code-behind.