I am sorry I can't solve what must be simple to everyone else even after reading so many posts. Simply stated... I have an ASP webpage I created in VS2010 and when the user clicks the 'Send Email' button, I want to change the button either using JQuery then calling my code-behind to do the actual send. Alternatively, I want the C# code behind to change the button text while it is in the process of sending so the user knows to hold on.
I am new to JQuery and still pretty new to C#. My website is www. themilwaukeehandcenter.com. If you click the contact us... this is where I want the code. I have tried
$("ContactUsButton").click(function () {
ContactUsLabel.Text = "Processing";
});
on the main page. I have also tried
protected void ContactUsButton_Click(object sender, System.EventArgs e)
{
ContactUsLabel.Text = "Sending... Please Wait";
ContactUsLabel.Refresh();
I know this should be simple but hours later.... reading so many posts later.... I feel no farther. I can't quite figure out how the JQuery onclick and the ASP onclick interact. I also don't know why C# flags the Refresh() as not valid. Any help welcome.
I actually placed a ContactUsLabel on the form too when I couldn't get the ContactUsButton to do what I intended. I am too knew to understand what you mean by 'How have you declared your button, but this is the code that creates it:
<asp:Button ID="ContactUsButton" runat="server"
OnClick="ContactUsButton_Click" Text="Send Email" Width="120px"/>
<asp:Label ID="ContactUsLabel" runat="server" Text="" Width="120px">
</asp:Label>
Your WinForm Code:
<asp:button id="ContactUsButton" runat="server" onclick="ContactUsButton_Click" cssClass="myButton" text="Contact Us" />
On submit use the jQuery script to change button text.
$(document).ready(function() {
$('.myButton').click(function(){
$(this).attr('value', 'Processing...');
});
});
View in fiddler: view
Finally at the server side:
protected void ContactUsButton_Click(object sender, System.EventArgs e)
{
ContactUsButton.Text = "Thank You";
}
Related
In my ASP.Net Web Form App, I have a button, and that button is suppose to launch an ajaxToolKit: ModalPopupExtender modal.
<asp:Button ID="uxTicketHistoryButton" runat="server" Text="Show Ticket History" style="color: blue;" OnClick="uxTicketHistoryButton_Click"/>
<ajaxToolkit:ModalPopupExtender ID="uxTicketHistoryModal" runat="server" PopupControlID="Panel1" TargetControlID="uxTicketHistoryButton"CancelControlID="btnClose" BackgroundCssClass="modalBackground"></ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" style = "display:none">
....
</asp:Panel ID>
I had asked a previous question on how to insert C# variable values into the modal, but it seems my problem there is that the modal seems to be interfering with my button click event function; essentially keeping it from firing. The function is suppose to get the data I need to plug into the modal once the button is clicked and the modal launched.
protected void uxTicketHistoryButton_Click(object sender, EventArgs e)
{
DataTable ticketHist = _dtMgr.GetContactInfoByName(uxContactDropdownList.SelectedValue);
string rName = ticketHist.Rows[0]["RequestorName"].ToString();
string rPhone = ticketHist.Rows[0]["RequestorPhone"].ToString();
....
}
I have noticed several odd things while debugging: 1) I put break points on the string variables (to see what the values were being returned) while debugging. After clicking the button, it goes right over the breakpoints (I assume that means its not "firing" that code.2) I can remove all of the code from inside the _Click function and the modal still launches when I click the button 3) If I comment out the modal code and click the button, the _Click event code fires fine and I can see the values for the string variables. So, I am assuming that the way I have the modal set (I suspect its related to using TargetControlID="uxTicketHistoryButton") is the problem. How do I get around my modal interfering with button click event? What am I doing wrong here?
Looks like you found one of those ajaxToolkit quirks. Try this:
Create a hidden button:
<asp:button id="hiddenButton" runat="server" style="display:none;" />
Change your Extender to target said button:
TargetControlID="hiddenButton"
Then in your _Click event, show the modal:
protected void uxTicketHistoryButton_Click(object sender, EventArgs e)
{
DataTable ticketHist = _dtMgr.GetContactInfoByName(uxContactDropdownList.SelectedValue);
string rName = ticketHist.Rows[0]["RequestorName"].ToString();
string rPhone = ticketHist.Rows[0]["RequestorPhone"].ToString();
....
uxTicketHistoryModal.Show();
}
I'm trying to add a button to the webpage, from the code behind. I have a single empty div on my main page that visible on and off, when needed. However the content I wish to create dynamically as the div content can change dependent on conditions.
I have realised that within my ASP Control I use a / (backslash) which cancels out my HTML. The problem I now have is understanding how I can get around this with code, is there a way to add ASP Controls to the web page? I am open to suggestions outside of the InnerHtml.
I'm creating my Button like so (in my Code Behind):
string buttonout = string.Format("<asp:Button ID=\"helpButton_0\" CommandArgument=\"0\" CssClass=\"HelpButton\" runat=\"server\" Text=\"?\"/>");
innercontent[0] = string.Format("<table><tr><td>Lead Passenger Information</td></tr><tr><td>Here by deafaul we used your detaisl from your profile, if you're not the lead passenger (As in you're booking for someone else) then please change details.</td></tr><tr><td>{0}</td></tr></table>"+ buttonout);
As Said above, The reason this doesn't work is because of InnerHtml hating backslashes, I think.
I do have a solution to this; and that's by adding more divs to the page.
<div id="HelpBoxDiv" runat="server" Visible="false">
<div id="HelpBoxDiv_Top" runat="server" Visible="true">
</div>
<div id="HelpBoxDiv_Bottom" runat="server" Visible="true">
<asp:Button ID="button_HelpBox_false" runat="server" />
</div>
</div>
I would then add my Innerhtml to the _Top Div, instead of the HelpBoxDiv which I am currently doing now. However this solution doesn't teach me anything.
I am hesitant to ask questions here, as I know a lot of question have been asked and I am sure this one has before, but I didn't find a solution. Any help is much appreciated.
Thank you.
I have realised that within my ASP Control I use a / (backslash) which
cancels out my HTML. The problem I now have is understanding how I can
get around this with code, is there a way to add ASP Controls to the
web page? I am open to suggestions outside of the InnerHtml.
You cannot add ASP.Net server control like a literal string.
Instead, you want to add the dynamic server control to the following approach -
ASPX
<asp:PlaceHolder runat="server" ID="PlaceHolder1"></asp:PlaceHolder>
Code Behind
protected void Page_Init(object sender, EventArgs e)
{
var button = new Button
{
ID = "helpButton_0",
CommandArgument = "0",
CssClass = "HelpButton",
Text = "?"
};
button.Command += button_Command;
PlaceHolder1.Controls.Add(button);
}
private void button_Command(object sender, CommandEventArgs e)
{
// Handle dynamic button's command event.
}
I am working on a project for school, and this is an extra credit part. I have a project started in VS 2010 using master pages, and what I'm trying to do is get a "Submit" button to redirect people to the "MyAccounts.aspx" page. My current code for the ASP part for the button looks like this:
<asp:Button ID="btnTransfer" runat="server" Text="Submit"/>
I have tried adding in the OnClick option, as well as the OnClientClick option. I have also added this code to the Site.Master.cs file as well as the Transfer.aspx.cs file:
protected void btnTransfer_Click(object sender, EventArgs e)
{
Response.Redirect(Page.ResolveClientUrl("/MyAccounts.aspx"));
}
When I run this and view the project in my browser, the whole thing runs fine, but when I click on the "Submit" button, it just refreshes the current page and does not properly redirect to the MyAccounts page. Anyone have any ideas for me?
You are doing it almost correctly, you just haven't put the correct pieces together. On Transfer.aspx, your button should be:
<asp:Button ID="btnTransfer" OnClick="btnTransfer_Click" runat="server" Text="Submit"/>
and your code behind should be like what #KendrickLamar said:
protected void btnTransfer_Click(object sender, EventArgs e)
{
Response.Redirect("~/MyAccounts.aspx");
}
The OnClick event tells it what to execute on post-back when the users clicks the button. This is in the code-behind for Transfer.aspx, not the site master.
I'm validating a form using a CustomValidator so I can colour the background of the textbox.
The code behind for the CustomValidator doesn't get called when I click the form's linkbutton. However, when I remove PostBackUrl="orderconfirm.aspx" the code does get called and works fine.
aspx page:
<asp:TextBox ID="txtBillingLastName" Name="txtBillingLastName" runat="server">/asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorLN" runat="server"
ControlToValidate="txtBillingLastName"
OnServerValidate="CustomValidatorLN_ServerValidate"
ValidateEmptyText="True">
</asp:CustomValidator>
<asp:LinkButton
ID="OrderButton" runat="server"
PostBackUrl="orderconfirm.aspx"
onclick="OrderButton_Click">
</asp:LinkButton>
code behind:
protected void CustomValidatorLN_ServerValidate(object sender, ServerValidateEventArgs args)
{
bool is_valid = txtBillingLastName.Text != "";
txtBillingLastName.BackColor = is_valid ? System.Drawing.Color.White : System.Drawing.Color.LightPink;
args.IsValid = is_valid;
}
I'm pretty new to .net/c# and to be honest I didn't get the answers to similar problems searched for on here.
Any help would be greatly appreciated.
Server side code runs when the page is requested, It doesn't work because you are posting back to(i.e. requesting) a different page, so the code never runs. You could post back to the original page then redirect in the code behind but the easiest solution is probably to eliminate orderconfirm.aspx entirely and just do everything in the original page.
For some reason, this code isn't working:
Code-Behind
protected void btnNote_Clicked(object sender, EventArgs e)
{
DevExpress.Web.ASPxPopupControl.ASPxPopupControl notePopup = (DevExpress.Web.ASPxPopupControl.ASPxPopupControl)Master.FindControl("TaskBar").FindControl("pcNote").FindControl("notePopup");
notePopup.ShowOnPageLoad = true;
}
.aspx (event)
<asp:Button ID="btnNote" runat="server" Text="Add Note" OnClick="btnNote_Clicked" />
I need to write a function that takes this popup control ('notePopup') and displays it, and I believe this is supposed to work, but for some reason, once the page is reloaded, there is no popup.
#Jordan, try to add the ASPxPopupControl inside the same MS UpdatePanel. In this case, I believe everything will work properly. What are your results?
I figured it out myself, although what I'm doing now I'm 100% sure I already did, and I'm not sure what else could have changed that affected my results since then, so I'm closing the question.