Multiline textfield in C# changes layout? - c#

I am using the ASP.net framework. I am building a web form using the design view of the .aspx file. I have made a very simple form, the below is the code in the .aspx file.
<asp:TextBox ID="TextBox3" runat="server" Height="60px" Width="550px" TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Height="60px" Text="Button" Width="100px"/>
<asp:Button ID="Button2" runat="server" Height="60px" Text="Button" Width="100px" />
The problem is that when I set the TextMode to MultiLine the position of buttons changes too.
Textmode set to single line:
Textmode set to multi line:
Any explanation for this?

Related

How create an ASP.NET C# that can generate its own field and and new panels?

I am trying to create a web app that can create a survey form just like google forms.
<asp:Panel ID="container" runat="server"></asp:Panel>
<asp:Panel ID="question" runat="server" Height="391px">
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Question: " Font-Size="Large"></asp:Label>
<asp:TextBox ID="txtQuestion" runat="server" Font-Size="Large"></asp:TextBox>
<asp:DropDownList ID="lstQuestionType" runat="server">
<asp:ListItem Enabled="False" Selected="True">Question Type</asp:ListItem>
<asp:ListItem>Short Answer</asp:ListItem>
<asp:ListItem>Paragraph</asp:ListItem>
<asp:ListItem>Multiple Choice</asp:ListItem>
<asp:ListItem>Check Box</asp:ListItem>
<asp:ListItem>Linear Scale</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnGenerate" runat="server" OnClick="btnGenerate_Click" Text="Generate Question" Width="137px" />
</asp:Panel>
<asp:Button ID="btnAddQuestion" runat="server" Text="Add Question" OnClick="btnAddQuestion_Click" />
and this is the C# code that generates the panel
protected void btnAddQuestion_Click(object sender, EventArgs e)
{
Panel newQuestions = new Panel();
newQuestions = question;
container.Controls.Add(newQuestions);
}
but when I click the add question button, it does not add the panel
Although i can't tell from the code probably the problem is with the question parameter. Also use MVC with controllers it will be much more clean and also VS automatically generates the View for you based on your models and controllers which i guess it will save you time in the long run.

asp panel default button property is not working in ie for live application

I have a page having multiple buttons and search functionality.I have placed one button and textbox in a panel.After writing seach text if I hit Enter,it works well for all the browsers on local, but for live application this is not working in IE.
The html is:
<asp:Panel ID="pnlSearch" runat="server" CssClass="search" DefaultButton="btnSearch">
<h2>
Explore QualityStocks without logging in</h2>
<asp:TextBox ID="txtSearch" CssClass="txt" runat="server" ToolTip="Stock Ticker" ></asp:TextBox>
<asp:Button TabIndex="0" ID="btnSearch" runat="server" ClientIDMode="Static" CssClass="btn" OnClick="btnSearch_Click" />
</asp:Panel>
What am I missing to do?
Thanks in advance,
Priya

asp.net Disable Button after Click while maintaining CausesValidation and an OnClick-Method

.aspx
<asp:TextBox ID="txtInvite" Width="170px" Height="20px" runat="server"
Font-Size="Small" ></asp:TextBox>
<AjaxToolkit:TextBoxWatermarkExtender ID="tbexInvite"
runat="server" SkinID="skinTextBoxWatermarkExtender"
TargetControlID="txtInvite" WatermarkText="Email"></AjaxToolkit:TextBoxWatermarkExtender>
<asp:RequiredFieldValidator ID="rfvInvite" runat="server"
Display="None" ValidationGroup="Inivitation" SetFocusOnError="true"
ControlToValidate="txtInvite" ErrorMessage="Enter Email."></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regExpInvite" runat="server"
Display="None" ValidationGroup="Inivitation" SetFocusOnError="true"
ValidationExpression="\s*\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*\s*"
ControlToValidate="txtInvite" ErrorMessage="Invalid Email Format."></asp:RegularExpressionValidator>
<div class="ButtonLogin" style="margin-top:-27px;margin-right:143px;_margin-right:105px;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:Button ID="btnInvite" runat="server" CssClass="cssLoginButton blue" Text="Invite" ToolTip="Invite" ValidationGroup="Inivitation" CausesValidation="true" onclick="btnInvite_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="0">
<ProgressTemplate>
<asp:Image ID="Image1" ImageUrl="~/App_Themes/Lifetrons/images/progressbar.gif" AlternateText="Processing" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
Page_load Code
.CS
this.btnInvite.Attributes.Add("onclick", "this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(this.btnInvite, "").ToString());
I want to disable button after clicking on it with maintaining validation and Onlick method. I refer to this question my problem is same like this question but I haven't solve my problem. How can I solve?
There is no need to mess around with your code-behind Page_Load event. In your button control, just add the following snippet:
OnClientClick="if(Page_ClientValidate('Inivitation')){this.disabled=true;}"
So that your button looks like
<asp:Button ID="btnInvite" runat="server" CssClass="cssLoginButton blue" Text="Invite"
ToolTip="Invite" ValidationGroup="Inivitation" CausesValidation="true"
onclick="btnInvite_Click" OnClientClick="if(Page_ClientValidate('Inivitation')){this.disabled=true;}" />
You should be able to disable the button using the Button_Click method. Make your first line something like this:
Button.Enabled = False;
There is a problem with this method though. If the page loads too quickly or the code freezes it will not disable the button properly. Just remember to re-enable the button at the end of the method if the validation fails or times out.
Another method you may try is to hide it using CSS. I am a big fan of this because it always works and it is very simple. You need a technology like jQuery where you can add classes on the fly. You can use the AddClass and RemoveClass API in jQuery to add/remove CSS classes at runtime. Take a look here. http://jqueryui.com/addClass/
you can use Like this
<asp:Button ID="btnInvite" runat="server" CssClass="cssLoginButton blue" Text="Invite" ToolTip="Invite" ValidationGroup="Inivitation" CausesValidation="true" UseSubmitBehavior = False"onclick="btnInvite_Click" />

Asp.net validators validate Disabled control

I have a Panel control that contains some control such as text boxes.I want to use asp.net validators to validate text boxes.But if Panle is disabled then text boxes become disabled but validators such as RequiredFieldValidator validate disabled text box.
<asp:Panel ID="Panel1" runat="server" Enabled="false">
<asp:TextBox ID="TextBox2" runat="server" />
<asp:RequiredFieldValidator runat="server" ErrorMessage="RequiredFieldValidator"
ForeColor="#FF3300" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
</asp:Panel>
How I can set for validators that don't validate disabled controls?
if some control is disabled you can set its property CausesValidation="False"
<asp:Button id="Button1" runat="server"
Text="Cancel" CausesValidation="False">
</asp:Button>
EDITED
can you do this way
if (!panel.Enabled)
{
RequiredFieldValidator1.Enabled = false;// disable your all validators
}
Add this line in Page_Load()
RequiredFieldValidator1.Enabled = panel.Enabled;

ASP.NET validation summary inside formview doesn't work

I have a validation summary inside a asp.net formview and the validators just don't seem to trigger the validation summary.
Things I already tried:
Enable the ViewState on everything.
Set the ClientID to static.
Set the ValidationGroup to the same group on both all validators and the summary.
Used Google to search for a solution.
Anyone has any ideas on how to handle this?
Code. Formview declaration:
<asp:FormView ID="FormViewPerson" runat="server" DataSourceID="ObjectDataSourcePerson"
DefaultMode="Edit" OnItemUpdating="FormViewPerson_ItemUpdating" OnItemCommand="FormViewPerson_ItemCommand"
OnItemUpdated="FormViewPerson_ItemUpdated" Width="100%">
Any of the textboxes with the validator:
<td> <asp:TextBox ID="NumberTextBox" runat="server" Text='<%# Bind("Number") %>'
TabIndex="10" CausesValidation="True" ClientIDMode="Static" />
<asp:RequiredFieldValidator ID="RequiredFieldValidatorNumber" runat="server" ControlToValidate="NumberTextBox"
ErrorMessage="Number is Required" ForeColor="Red"
ValidationGroup="EditPerson">*</asp:RequiredFieldValidator>
</td>
And the submitbutton:
<asp:ValidationSummary ID="ValidationSummaryPerson" runat="server"
ForeColor="Red" ClientIDMode="Static" CssClass="validation"
ShowMessageBox="True" ValidationGroup="EditPerson" ViewStateMode="Enabled"
/>
<asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Save" ValidationGroup="EditPerson" CssClass="ButtonStyle" TabIndex="90" />
<asp:Button ID="EditCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel" CssClass="ButtonStyle" TabIndex="100"
ValidationGroup="EditPerson" />
Hope the CausesValidation for the button is set to true.
Well, I fixed the issue. If anyone else encounters this problem try the following:
Ensure there is only one (1) validation group on the entire form.
Set "causesvalidation" to "true" on the submitbutton.
Check, double check and triple check the spelling of your validationgroup property on all relevant controls.
Be on the lookout for javascript errors in your client-side scripts. They can cause havoc.

Categories

Resources