I wanted to create a pop-up with option buttons and textbox..
check my codes..
<form id="frmInsuranceCarrier" runat="server">
<div>Enter a New Insurance Carrier Code</div>
<div>
<asp:RadioButton ID="optAutoAssign" runat="server" />
Auto Assign</div>
<div>
<asp:RadioButton ID="optManual" runat="server" />
Manual</div>
<div>
<asp:TextBox ID="txtManual" runat="server"></asp:TextBox>
</div>
<asp:Button ID="cmdOk" runat="server" Text="Ok" onclick="cmdOk_Click" />
<asp:Button ID="cmdCancel" runat="server" Text="Cancel"
onclick=
"cmdCancel_Click" />
there's not much code here in dealing with a popup : )
Do you want an ajax modal popup? in that case check out:
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpopup.aspx
Jquery model is a good choice.
How to use jquery dialog in asp.net
jQuery UI Dialog
you can use the RegisterStartupScript
to execute every javascript/jQuery Code Serverside
public void AnyButton_Click(Object sender, EventArgs e)
{
string script = "$('#theid').dialog('open');";
ClientScript.RegisterStartupScript(GetType(), "popup", script, true);
}
Related
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.
I have some code inside of an asp:UpdatePanel that after clicking a button. it'll will hide a Label and replace that with an editable Textbox. This functionality all works fine within the UpdatePanel, however after clicking this button to make the call (which is also inside of the UpdatePanel), it causes asp:LinkButtons that appear after and outside of the UpdatePanel not to work anymore. These links work prior to interacting with controls inside of the UpdatePanel, but stop working after the fact. It's worth noting that these linkbuttons are dynamically created and appended to an existing div that follows and is not inside the UpdatePanel causing this issue. For good measure I tried calling the method that dynamically creates and appends these controls whenever the update panel made a callback to the server, but to no avail.
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<label class="reportModeLabel">Primary Mode: </label>
<div id="divShowMode" runat="server" class="inlineItem">
<asp:Label ID="lblPrimaryMode" runat="server"></asp:Label>
<asp:LinkButton ID="lnkPrimaryMode" runat="server" CssClass="clickOnce" OnClick="lnkPrimaryMode_Click">
<asp:Image ID="imgChangePrimaryMode" runat="server" CssClass="imgReportUpdateMenuItem" ImageUrl="~/Images/Edit.png" />
</asp:LinkButton>
</div>
<div id="divUpdateMode" runat="server" class="inlineItem" >
<asp:DropdownList ID="ddlModeOfTransmission" runat="server" Width="40%" CssClass="metaItemDropdown">
<asp:ListItem Text="Food" Value="1"></asp:ListItem>
<asp:ListItem Text="Water" Value="2"></asp:ListItem>
<asp:ListItem Text="Animal" Value="3"></asp:ListItem>
<asp:ListItem Text="Person to Person" Value="4"></asp:ListItem>
<asp:ListItem Text="Environmental" Value="5"></asp:ListItem>
<asp:ListItem Text="Other/Unknown" Value="6"></asp:ListItem>
</asp:DropdownList>
<asp:LinkButton ID="lnkPrimaryModeSave" runat="server" CssClass="clickOnce" OnClick="lnkPrimaryModeSave_Click">
<asp:Image ID="imgPrimaryModeSave" runat="server" ImageUrl="~/Images/Check-Selected.png" />
</asp:LinkButton>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="divWizardMenu">
//The link button controls that no longer work after using the
//UpdatePanel are dynamically created on server and added here
<ul id="ulMainMenu" runat="server"/>
</div>
//UpdatePanel ajax calls
protected void lnkPrimaryMode_Click(object sender, EventArgs e)
{
divShowMode.Visible = false;
divUpdateMode.Visible = true;
ddlModeOfTransmission.SelectedValue = Record.PrimaryModeOfTransmissionID.ToString();
}
protected void lnkPrimaryModeSave_Click(object sender, EventArgs e)
{
divUpdateMode.Visible = false;
divShowMode.Visible = true;
}
Are you assigning your dynamically created LinkButtons an ID when you create them?
I think they will need the ID to be set so that Events can be rewired up on Postback.
My simple question is that ,is there any method/way in which 'Checbox' only check one time.I mean when page loaded which contains 'checkbox' ,after page loaded then i select check box and press 'button' then checkbox will be disabled,only one time checkbox will tick.Is there any way?
Thanks.
here is my code :
<label>Allow Null <asp:CheckBox ID="Null" runat="server" /></label>
<label>Primary Key <asp:CheckBox ID="Primary" runat="server" />
<br />
<asp:Button ID="Button1" ValidationGroup="s" onclick="Button1_Click" runat="server" Text="Insert" />
I want when i press "Insert" button then primary checkbox(check its tick or not),if Primary cehckbox tick then next time this will be disabled.Only one time "Primary" checkbox tick.
As the coments suggests ,
from client script you can try this:
$("#checkId").attr("disabled", true);
if you are in asp.net web-forms and the button does postback then you can even disable it from code behind.
Edit
<label>Allow Null <asp:CheckBox ID="Null" runat="server" ClientIdMode="Static" /></label>
<asp:Button ID="Button1" ValidationGroup="s" onclick="Button1_Click" runat="server" OnClientClick="UpdateCheck();" Text="Insert" />
<script>
function updateCheck(){
$("#Null").attr("disabled", true);
}
</script>
I have ASP.Net page where i am calling a JavaScript function like this:
Enter server name: <asp:TextBox ID="txt_name" runat="server"></asp:TextBox>
<asp:Button ID="btn_view" runat="server" OnClick="View_btn_click" OnClientClick="return AlertOnGo('View Configuration',document.getElementById('<%= txt_name.ClientID %>').value)" Text ="GO!" />
But on clicking the GO button, i am getting the following error:
JavaScript runtime error: Unable to get property 'value' of undefined or null reference
On viewing the rendered code for the button:
<input type="submit" name="btn_view" value="GO!" onclick="return AlertOnGo('View Configuration',document.getElementById('<%= txt_name.ClientID %>').value);" id="btn_view" />
It is not putting the appropriate ClientID. I tried setting the CLientIDMode to static for the test box, yet no help.
This question is similar to this unanswered question.
There are a few solutions to this problem.
One of the simpler would be to move the name into a JavaScript variable since the problem only occurs within the control when trying to evaluate txt_name.ClientID inside the OnClientClick attribute of an ASP.NET control.
<script>
var txtName = '<%= txt_name.ClientID %>';
</script>
Enter server name: <asp:TextBox ID="txt_name" runat="server"></asp:TextBox>
<asp:Button ID="btn_view" runat="server" OnClick="View_btn_click"
OnClientClick="return AlertOnGo('View Configuration',
document.getElementById(txtName).value)" Text ="GO!" />
you can use the property ClientIDMode="Static" inside the asp:textbox tag
like this
<asp:TextBox ClientIDMode="Static" ID="txt_name" runat="server"></asp:TextBox>
<asp:Button ID="btn_view" runat="server" OnClick="View_btn_click"
OnClientClick="return AlertOnGo('View Configuration',
document.getElementById(txtName).value)" Text ="GO!" />
this way the client id of the text box would be same as the "id" and you can use
document.getElementById('txt_name').value
and it works for me
Youre using <%= %> in the property of an asp.net web control - I wouldnt expect that to work, since the whole control will be replaced by html.
I would move your javascript out into a script block and attach the event handler in code rather than putting it all inline.
Enter server name: <asp:TextBox ID="txt_name" runat="server"></asp:TextBox>
<asp:Button ID="btn_view" runat="server" OnClick="View_btn_click" Text ="GO!" />
<script>
document.getElementById('<%= btn_view.ClientID %>').attachEvent('click', function() {
return AlertOnGo('View Configuration',
document.getElementById('<%= txt_name.ClientID %>').value);
});
</script>
-- edited answer --
aspx
<asp:Button ID="btn_view" runat="server" OnClick="View_btn_click" OnClientClick="javascript:return AlertOnGo('View Configuration');" Text ="GO!" />
script
function AlertOnGo(mode)
{
var btnId = '<%= txt_name.ClientID %>';
var value=document.getElementById(btnId).value;
//your code
return false;
}
I prefer to use String.Concat. You can use \u0027 instead of apostrophe.
OnClientClick='<%#String.Concat("document.getElementById(\u0027", AddToCartBtn.ClientID.ToString(), "\u0027).value = \u0027Adding...\u0027;")%>'
Another solution is you can go to browser do insect element read the dynamic Id of textbox and set that in javascript like:
var ddlFunction = document.getElementById('ctl00_SPWebPartManager1_g_ecede3f6_2b87_405a_af1b_70401bb8d4c7_ddlFunction');
Html:
<asp:DropDownList ID="ddlFunction" runat="server" CssClass="dropDownClass">
<asp:ListItem Selected="True">Select One</asp:ListItem>
<asp:ListItem>Sample 1</asp:ListItem>
<asp:ListItem>Sample 2</asp:ListItem>
</asp:DropDownList>
You can create a css class and use that instead of client id, (with jQuery $('.txt_name').text()):
Enter server name:
<asp:TextBox ID="txt_name" CssClass="txt_name" runat="server"></asp:TextBox>
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.