I have tried this several ways and none of them seem to work for me. I have a formview and when the user goes into the edit mode and then clicks update I want a modal popup to show so they can type a note as to what they changed.
Here is my code
<ajaxToolkit:ModalPopupExtender ID="SubmitButton_ModalPopupExtender"
runat="server" OkControlID="EditNoteButton" PopupControlID="EditNotePanel"
BehaviorID="MPE" BackgroundCssClass="modalBackground"
TargetControlID="DummyButton">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="EditNotePanel" runat="server" CssClass="style105" Height="23px" style="display: none">
<asp:TextBox ID="EditNoteBox" runat="server" CssClass="style106" Height="68px" Width="223px">What Did You Change?</asp:TextBox> <br />
<asp:Button ID="EditNoteButton" runat="server" CssClass="style107" Height="29px" Text="Ok" Width="52px" CommandName="update" /> <br />
</asp:Panel>
C#
protected void ClientInformationForm_ItemCommand(Object sender, FormViewCommandEventArgs e)
{
//case statements
if (ClientInformationForm.CurrentMode == FormViewMode.Edit)
{
SubmitButton_ModalPopupExtender.TargetControlID = ((Button)ClientInformationForm.FindControl("SubmitButton")).UniqueID;
}
From what I have read that should work. I have tried showing it through javascript on clientclick. I have tried displaying it by calling modal.show() in the itemcommand but none of them are displaying it. Does it matter if the panel or popup are inside or outside the formview?
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack && Session["CurrentAccountId"] != null)
{
AddressTypeddl.DataBind();
ShippingAddressddl.DataBind();
AddressForm.DataBind();
}
if (ClientInformationForm.DataItemCount == 0)
{
ClientInformationForm.BackColor = Color.FromArgb(0xd9e2bf);
}
else
{
ClientInformationForm.BackColor = Color.White;
}
if (Session["CurrentAccountId"] == null)
{
NoteBox.Visible = false;
NewNoteButton.Visible = false;
NoteTypeddl.Visible = false;
NoteLabel.Visible = false;
NoteTypeLabel.Visible = false;
NewNoteLabel.Visible = false;
CreditCardView.Visible = false;
NewAccountButton.Visible = true;
AddressTypeddl.Visible = false;
AddressLabel.Visible = false;
AddressForm.Visible = false;
}
else
{
NoteBox.Visible = true;
NewNoteButton.Visible = true;
NoteTypeddl.Visible = true;
NoteLabel.Visible = true;
NoteTypeLabel.Visible = true;
NewNoteLabel.Visible = true;
CreditCardView.Visible = true;
NewAccountButton.Visible = false;
AddressTypeddl.Visible = true;
AddressLabel.Visible = true;
AddressForm.Visible = true;
}
}
So I just realized if I want people to keep posting I need to edit my original post and not just add a note, so hopefully this helps. Anyway, I still can't get this to work and I don't know what is causing my popup not to fire?
If you want to pop up the modal after the user makes their edits, I wouldn't use the ItemCommand event.
I haven't used FormViews much, mostly GridViews. But I'm assuming that the principles are mostly the same.
Have you tried showing the modal in the ItemUpdated event?
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.itemupdated(v=vs.110).aspx
I haven't tried this before, but I'd like to think that something like this may work:
protected void ClientInformationForm_ItemUpdated(Object sender, FormViewUpdatedEventArgs e)
{
//capture ID of the updated record, and perhaps store it in a HiddenField that's in the modal
SubmitButton_ModalPopupExtender.Show();
}
Well after many days of trail and error I finally found out why this wasn't working. It came down to the dummy button. I was setting visible to false to hide the button and for some reason that doesn't work. Once I changed it to style= display:none; it fired fine. Weird that there was no error thrown it was just never popping up.
Related
BillingEntity = (string)rdr["BillingEntity"];
string[] split = BillingEntity.Split(',');
for (int i = 0; i < split.Length; i++)
{
split[i] = split[i].Trim();
if (split[i] == "Clinic")
{
BillingEntityCheckBox.Items[i].Checked = true;
Session["billingEntitySessionVar"] = Session["billingEntitySessionVar"]
+ " Clinic";
}
How can I check an item in a checkbox list from the underlying code?
I know with a single checkbox you use checkbox.checked = true. I had that working fine in my code, but I need to link the checkboxes together in a control so that I can trigger an event based on whether any of them has been changed by the user.
To give a little background, I'm pulling in data from a SQL database and outputting to the user interface through a WebForm.
I think you're missing the concept of databinding, is this what you're looking for?:
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] myStrings = new string[] { "Example Value", "Not a Thing", "Many Things", "All the Thing" };
cblThingy.DataSource = myStrings;
cblThingy.DataBind();
}
protected void btnPushMe_Click(object sender, EventArgs e)
{
//for all the things
foreach(ListItem itemThing in cblThingy.Items)
{
//set a default of not selected
itemThing.Selected = false;
//if the text is the same
//you can have any check you like here
if (itemThing.Text == txtThing.Text)
//say that it's selected
itemThing.Selected = true;
}
}
}
^The "code behind"
<asp:Label ID="lblThing" runat="server" Text="If you type the text and push the button the thing with select." />
<asp:TextBox ID="txtThing" runat="server" Text="Example Value" />
<asp:Button ID="btnPushMe" runat="server" Text="Push My Button" OnClick="btnPushMe_Click" />
<asp:CheckBoxList ID="cblThingy" runat="server" />
^The webform xml
Hopefully that helps!
p.s. I think it would be a good idea to make a readonly property on the BillingEntity type, which would return a bool which does the check for "clinic" inside that class, making it more object oriented..
This seems to be an easy one but got stuck on it last few hours. I've a search button that fires up PostBackUrl. The issue is it only fires up when I click the search button for the second time. Here what I did:
Default.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = "View Cities - CcmApp";
if (!IsPostBack)
{
BindGridView(0);
BindPager(0);
GetCountries();
}
}
protected void SearchButton_Click(object sender, EventArgs e)
{
City aCity = new City();
aCity.CityName = nameTextBox.Text;
if (nameTextBox.Text.Length == 0 && radioCityName.Checked == true)
{
labelMsg.Visible = true;
labelMsg.Text = "No search term given";
}
else
{
SearchButton.PostBackUrl = GetDefaultUrl();
}
BindGridView(0);
BindPager(0);
}
public string GetDefaultUrl()
{
return "SearchCity.aspx?SearchTerm=" + nameTextBox.Text;
}
Default.aspx:
<asp:LinkButton ID="SearchButton" runat="server" Text="Search" ValidationGroup="vdGroup"
CssClass="btn btn-primary" OnClick="SearchButton_Click"></asp:LinkButton>
I am not sure what causes it click second time to get the url. Is there any way to get over it?
Note: I am expecting to get the following output in the url -
http://localhost:1234/UI/SearchCity.aspx?SearchTerm=a. But works only on second button click. When I click for the first time, I get this - http://localhost:1234/UI/SearchCity.aspx
The PostBackUrl url on the button is only set AFTER the first PostBack. If you would set it in Page_Load for example you will see that it will work on the first PostBack.
If you want the ?SearchTerm= in the url only when there is content in nameTextBox you could use Response.Redirect or accept that there is no data in ?SearchTerm=.
Better still check on the Clientside if nameTextBox has text and prevent the button click using a Validator.
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="/Default.aspx?SearchTerm=" ValidationGroup="mySearch">Search</asp:LinkButton>
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="nameTextBox" ClientValidationFunction="checkLength" ValidateEmptyText="true" ErrorMessage="Min. 3 characters required" ValidationGroup="mySearch"></asp:CustomValidator>
<script type="text/javascript">
function checkLength(oSrc, args) {
var v = document.getElementById("<%=nameTextBox.ClientID %>").value;
if (v.length < 3) {
args.IsValid = false;
} else {
$("#<%=LinkButton1.ClientID %>").attr("onclick", $("#<%=LinkButton1.ClientID %>").attr("onclick").replace("?SearchTerm=", "?SearchTerm=" + v));
args.IsValid = true;
}
}
</script>
I'm trying to show 2 link buttons in the master page, but these buttons should be Enable/Disable according to the content page. I already retrieve the information from the content page, and it works well, the only thing is that I can't turn enable the buttons once I have disabled them. I have tried several ways, but every attempt seems to do the same. Here is my code.
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
ASPxListBox listBoxSA = new ASPxListBox();
listBoxSA = (ASPxListBox)ContentPanelHidden.FindControl("ASPxListBox2");
if (listBoxSA != null)
{
if (listBoxSA.Items.Count > 0)
{
EnableButtons(true);
}
else
{
EnableButtons(false);
}
}
}
else
{
EnableButtons(false);
}
}
public void EnableButtons(Boolean enable)
{
btnNext.Enabled = enable;
btnPrint.Enabled = enable;
}
PS. The boolean is changing its value, but the button is always disabled
I would enclose these buttons in an update panel and tell the update panel to update itself after setting the Enabled property. That should update the buttons with only a partial page update.
HTML
<asp:UpdatePanel ID="MyUpdatePanel" runat="server" UpdateMode="Conditional" ClientIDMode="Static">
<ContentTemplate>
... buttons here ...
</ContentTemplate>
</asp:UpdatePanel>
CODE BEHIND
public void EnableButtons(Boolean enable)
{
btnNext.Enabled = enable;
btnPrint.Enabled = enable;
MyUpdatePanel.Update();
}
because you are using is post back property, once it disabled you should do a post back from your current page and also listBoxSA should not be null.
I have the following if-statement, that occurs on Page.IsPostBack, why is FirstName.Visible, LastName.Visible, EmailAddress.Visible all false?:
protected void Page_Load(object sender, EventArgs e)
{
MainLogo.InnerHtml = ModuleEval("HeadlineLandingPage").ToString();
FillLabelsAndImages();
if (!Page.IsPostBack) //Page load
{
//Some random code here
}
else //Submit button load
{
MainLogo.InnerHtml = ModuleEval("HeadlineLandingMasterPage").ToString();
if (FirstName.Visible && LastName.Visible && EmailAddress.Visible)
{
if (detailsResponse.ResponseStatus.Success && detailsResponse.MemberInfo != null)
{
//Random code here
}
else
HandleWebServiceError(detailsResponse.ResponseStatus);
}
else
{
}
}
}
The elements are invisible by default:
<input type="text" id="FirstName" runat="server" visible="False" />
However they are set to visible when some user actions occur:
FirstName.Visible = true;
The elements are all clearly visible when I submit, I don't understand why asp.net still thinks they are invisible.
How are you changing the control?
If you've got something to the effect of
protected void Page_Load(object sender, EventArgs e)
{
if(FirstName.Visible && LastName.Visible && EmailAddress.Visible)
{
//Code
}
}
protected void UpdateFirstName(object sender, EventArgs e)
{
FirstName.Visible = true;
}
And you call the update by using an ASP.NET event, such as
<asp:button text="Button!" onclick="UpdateFirstName" runat="server" />
When you click on the button Page_Load is called first. While Page_Load is running,
FirstName.Visible
Would be whatever the default value is - in this case, false.
Unfortunately there isn't really a way to call UpdateFirstName before Page_Load.
The best solution is to move your
if(FirstName.Visible && LastName.Visible && EmailAddress.Visible)
logic into a different function which can be called after UpdateFirstName runs.
Elements rendered via asp.net controls will not render in the page at all if they are set to visible=false. IE: The element will not be in the output.
Regular html elements do not understand this and therefore you must set style="display:none" to hide them while still making them available in the DOM/rendered output.
So if what you are using is not an asp.net control setting the value visible="false" on the element, as you show for your input element:
<input type="text" id="FirstName" runat="server" visible="False" />
Really does nothing except placing an attribute on the element called visible which has a value of False.
For example:
If I put the following in an asp.net page.
<input id="test" runat="server" />
<asp:TextBox ID="test1" runat="server"></asp:TextBox>
And then on the server side I run the following:
protected void Page_Load(object sender, EventArgs e)
{
test.Style.Add("display", "none");
test1.Visible = false;
}
The rendered output will be something similar to this:
<input name="ctl00$FeaturedContent$test" type="text" id="FeaturedContent_test" style="display:none;" />
With no sign of the element test1 in the rendered output.
While the element test is in the output except that it does not appear as a visible element on the page.
Hope that helps.
Have you tried?
if (FirstName.Visible == true && LastName.Visible == true && EmailAddress.Visible == true)
{
//your code here
}
Your testing against a boolean and it really shouldn't matter but it's worth a try. According to MSDN the .Visible property "Gets or sets a value indicating whether the control and all its child controls are displayed.". So your getting the value but you still need to test against that value.
I face so strange action in my page.
I have a radio button list, according to the selection i execute specific code.
The problem is:
for example when i select option 2 then i select back option 1.
the page maintains the state(all the drop down lists maintain their previous selections) and i need to click the link one more time to force the page to enter this condition:
if (!Page.IsPostBack)
{
BindCamp(0);
BindCamp(1);
}
my aspx :
<asp:RadioButtonList ID="rbl" runat="server"
OnSelectedIndexChanged="rbl_SelectedIndexChanged"
RepeatDirection="Horizontal" Width="200px" AutoPostBack="True">
<asp:ListItem Value="0" Selected="True">view data</asp:ListItem>
<asp:ListItem Value="1">view report</asp:ListItem>
</asp:RadioButtonList>
My code:
protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
{
if (rbl.SelectedItem.Value == "0")
{
pnl_view.Visible = true;
pnl_stat.Visible = false;
pnl_rep.Visible = false;
}
else
{
pnl_view.Visible = false;
pnl_all.Visible = false;
pnl_Dean.Visible = false;
pnl_research.Visible = false;
pnl_stat.Visible = true;
}
}
Per your comments, DLL's will always retain their values unless you manually set the selection, you set EnableViewState="false" (which disabled all viewstate then). So I think you may need code that does:
ddl.SelectedIndex = 0; // or -1 depending on whether you want an item selected
Upon clicking the next radio button.