Adding the resize function to an asp textbox - javascript

In an there is the function at the bottom right corner to drag and change the size of the box, is there a way of adding it to an asp textbox?
Textbox is as follows:
<div class="control">
<asp:TextBox runat="server" ID="TextBox1" Width="100%" EnableViewState="false" ViewStateMode="Disabled" />
<asp:Label runat="server" ID="Label1" Visible="false" ViewStateMode="Disabled" EnableViewState="false" AssociatedControlID="TextBox1" />
</div>

Set the attribute TextMode="multiline", you can still set Rows="1" if you want it initially to look like a textbox/text input.

Related

asp.net Control visibility

I have a aspx form in which there are 5 controls below is the design code:
Question
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList><br />
Answer
<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
<asp:CheckBox ID="CheckBox1" runat="server" Text="If Other" AutoPostBack="True"
OnCheckedChanged="CheckBox1_CheckedChanged" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
A user selects a question from the drop down list and chooses the answer from the answer list.
If he/she doesn't find the answer in drop down list than he/she selects the checkbox and type the answer in textbox and press the submit button afterwards.
Is it possible to show the textbox and at the same time hide the drop down list using a single line code in checkbox OnCheckedChanged event?
Yes (though I'd use some more lines for better readability), you should set the visibility of the TextBox to false, to hide it at first:
<asp:TextBox ID="TextBox1" runat="server" Visible="false"></asp:TextBox>
In CheckBox1_CheckedChanged, you add the following lines:
DropDownList2.Visible = !CheckBox1.Checked;
TextBox1.Visible = CheckBox1.Checked;

How can I stop auto post back on selecting the radio buttons which shows grid on selecting Yes

------Code for Radio Buttons. On selecing Yes page is postback and on selecting No also page auto post back. I want not to post back page on selecting No. Please help
<asp:Panel TabIndex="-1" runat="server" ID="pnlMedicalLicenseInfo">
<asp:RadioButton ID="rboMedicalLicenseYes" AutoPostBack="true" Checked="true" Value="1" runat="server" GroupName="rboMedicalLicense" ClientIDMode="Static"></asp:RadioButton>
<asp:RadioButton ID="rboMedicalLicenseNo" AutoPostBack="true" Value="0" runat="server" GroupName="rboMedicalLicense" ClientIDMode="Static" />
<asp:CustomValidator ID="cusValMedicalLicense" Display="Dynamic" Enabled="false" runat="server" ClientValidationFunction="rbtnMedicalLicenseValidate" ValidationGroup="SD" CssClass="DisplayErrorMessage HideControl">
<%=base.GetResourceValue("WUCStudyDetailsNonHuman_cvrbPaidDirectly") %>
</asp:CustomValidator>
<span class="DisplayErrorMessage" style="display: none" id="divMedicalLicenseErr">
<%=base.GetResourceValue("WUCStudyDetailsNonHuman_divMedicalLicenseErr") %>
</span>
</asp:Panel>
This setting is what tells the control to post-back automatically:
AutoPostBack="true"
If you don't want that, simply remove that attribute from your controls:
<asp:RadioButton ID="rboMedicalLicenseYes" Checked="true" Value="1" runat="server" GroupName="rboMedicalLicense" ClientIDMode="Static"></asp:RadioButton>
<asp:RadioButton ID="rboMedicalLicenseNo" Value="0" runat="server" GroupName="rboMedicalLicense" ClientIDMode="Static" />

Button in asp.net doesn't work sometimes

I have a textbox and a button in my code.The button when clicked should validate the value entered in the textbox.The button most of the times does it but at times doesn't do anything at all.Any help would be appreciated.
<asp:Button ValidationGroup="vgpPno" runat="server" ID="btnSubmitPartNumber" OnClick="btnSubmitPartNumber_Click" SkinID="MSWButton" Text="OK" OnClientClick="if(Page_ClientValidate(){startPLI();}meta:resourcekey="btnSubmitPartNumberResource1" />
<asp:TextBox runat="server" ValidationGroup="vgpPno" SkinID="MSWTextBox"
ID="tbPARTNUMBER" MaxLength="11" meta:resourcekey="tbPARTNUMBERResource1" Width="230" Style="display: inline" CssClass="form-control input-sm"></asp:TextBox>
<asp:Button ValidationGroup="vgpPno" runat="server" ID="btnSubmitPartNumber" OnClick="btnSubmitPartNumber_Click" SkinID="MSWButton" Text="OK"
OnClientClick="if(Page_ClientValidate(){startPLI();}meta:resourcekey='btnSubmitPartNumberResource1'" />
Check Your web Form. If you are using form tag more then one time asp.controls not working properly

asp.net - javascript better way to use onchange with multiple fields

I have a asp.net web page which contains many textboxes.
If any of these boxes I run some javascript via the onchange event of each field.
The javascript basically changes a textbox to 'Y' so I know which section of the page has changed something.
Everything works fine, however I just need to know if there is a way of making the onchange call better/shorter ? Since I have over >100 textboxes, there is a lot of repetitive onchange='CM('3'); on each and every textbox, so I am hoping there is a better way to handle this.
There are three divs, each containing some 35 textboxes, so perhaps there is a way of doing it by DIV, which I don't know.
Any guidance is appreciated.
<asp:TextBox ID="txtDC1_D" runat="server" CssClass="STD_desc160" onchange="CM('3');"></asp:TextBox>
<asp:TextBox ID="txtDC1_C" runat="server" CssClass="STD_cur30" onchange="CM('3');"></asp:TextBox>
<asp:TextBox ID="txtDC1_1" runat="server" CssClass="STD_value55" onchange="CM('3');"></asp:TextBox>
<asp:TextBox ID="txtDC1_2" runat="server" cssClass="STD_value55" onchange="CM('3');"></asp:TextBox>
<asp:TextBox ID="txtDC1_3" runat="server" cssClass="STD_value55" onchange="CM('3');"></asp:TextBox>
<asp:TextBox ID="txtDC1_B" runat="server" CssClass="STD_bassis" onchange="CM('3');"></asp:TextBox>
<br />
<asp:TextBox ID="txtDC2_D" runat="server" CssClass="STD_desc160" onchange="CM('2');"></asp:TextBox>
<asp:TextBox ID="txtDC2_C" runat="server" CssClass="STD_cur30" onchange="CM('2');"></asp:TextBox>
<asp:TextBox ID="txtDC2_1" runat="server" CssClass="STD_value55" onchange="CM('2');" ></asp:TextBox>
<asp:TextBox ID="txtDC2_2" runat="server" cssClass="STD_value55" onchange="CM('2');" ></asp:TextBox>
<asp:TextBox ID="txtDC2_3" runat="server" cssClass="STD_value55" onchange="CM('2');" ></asp:TextBox>
<asp:TextBox ID="txtDC2_B" runat="server" CssClass="STD_bassis" onchange="CM('2');"></asp:TextBox>
<br />
If jQuery is also an option ( which I strongly recommend) , so :
$(function (){
$("input[type=text]").on('change',function (){
if ($(this).val()) $(this).val('Y'); else $(this).val('');
})
});
if not , I will delete this answer.

FileName of fileupload is empty after a partial postback of an updatepanel?

I have a FileUpload in the Updatepanel.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<Triggers>
<asp:PostBackTrigger ControlID="SaveButton" />
</Triggers>
<ContentTemplate>
<cc1:TabContainer CssClass="visoft__tab_xpie7" runat="server" ID="tab" ActiveTabIndex="0" Width="100%" Font-Size="11px">
<cc1:TabPanel runat="server" HeaderText="اطلاعات پایه" ID="TabPanel1">
<ContentTemplate>
<div class="row">
<span style="width: 100px" class="rowtitle">تصویر </span>
<asp:FileUpload ID="ImageFileUpload" runat="server"/>
<asp:ImageButton ID="RemoveImageButton" runat="server" ImageUrl="~/images/delete.png" />
</div>
<div class="row">
<span style="width: 100px" class="rowtitle">Category</span>
<asp:DropDownList ID="CategoryDropDownList" runat="server" Width="200px" AutoPostBack="True" DataTextField="Name" DataValueField="ID" OnSelectedIndexChanged="CategoryDropDownList_SelectedIndexChanged" />
<asp:RequiredFieldValidator ID="CategoryRFV" runat="server" ControlToValidate="CategoryDropDownList" ForeColor="Red" ValidationGroup="Save" ErrorMessage="مجموعه را انتخاب کنید." Text="*" />
</div>
<div class="row" style="height: 300px">
<span style="width: 100px" class="rowtitle">توضیحات کامل</span>
<editor:HtmlEditor Style="float: left" runat="server" Width="600px" ID="DescriptionHtmlEditor" />
<asp:RequiredFieldValidator Text="*" ID="DescriptionRFV" runat="server" ControlToValidate="DescriptionHtmlEditor" ForeColor="Red" ValidationGroup="Save" ErrorMessage="توضیحات را وارد کنید ." />
</div>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
<div class="row" style="text-align: center">
<asp:Button ID="SaveButton" class="button" Width="100px" OnClick="SaveButton_Click" runat="server" ValidationGroup="Save" Text="ذخیره" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
when i was trying to access the FileUpload FileName property after a partial postback of an updatepanel, it was empty.
I want get Filenme of uploadpanel in oncange event witj javascrip, but i don't get Fullpath of file.
function FileChange()
{
var filename = document.getElementById('<%= FileNameUpload.ClientID %>');
var file = document.getElementById('fileupload');
filename.value = file.value;
}
How to get filename of fileupload after partial postback?
When i was trying to access the FileUpload FileName property after a
partial postback of an updatepanel, it was empty.
Update Panels simply intercept the regular form submit and perform a FULL postback using an xmlhttp request. Because of this, the selection initially made on the input:file element was already submitted in the initial postback and you can't read it anymore afterwards. To prove what I am saying, try and read the file name on the initial postback and you'll see that you'll be able to.
Looking at your code, it also seems that you are trying to set the value of fileupload element programmatically. This is not possible either for security reasons - you can't access a user's hard drive from Javascript and decide which file the user should upload to your website. Once the user selected the file and the form was submitted, the selection is gone; the user would have to re-select the file himself.
You can try many hacks to make this work with UpdatePanels, but the cleanest in the long run is to implement this using jQuery Ajax because you have complete control of what gets submitted and what doesn't and when.
I hope this helps clarifying why your approach won't work.

Categories