VIsual Web Developer Radio Button - Update Live - c#

I am currently trying to develop a form/website using Microsoft Visual Web Developer 2010 Express.
In the first section is a group of radio buttons which control the subject line field. I have been able to add a RadioButtonCheckedControl attribute which will set the subject line BUT it will only work if the page is refreshed. Is there a command to live update the form?
In the ascx file there is the following:
<asp:RadioButton ID="RadioUniform" runat="server" Text="Uniform Infringement"
GroupName="Reason" oncheckedchanged="RadioUniform_CheckedChanged" />
And then in the ascx.cs file there is the following:
protected void RadioUniform_CheckedChanged(object sender, EventArgs e)
{
CommentSubject.Text = "UNIFORM INFRINGEMENT";
}

So after a couple of quick Google searches (as I've done previous nights) I found the solution. After the OnCheckedChanged part of the radio button code, add AutoPostBack="True".

Related

How to change view in asp.net?

Im wondering how i can change "views" with a button click in Visual Studio (asp.net)?
I have 2 .aspx files, one called Default.aspx and another one called Library.aspx. How can i make a button change the views to display the other aspx file?
I tried googling but didnt find anything useful. Any help here is appreciated. Thanks
Ok, assuming default.aspx is in desing mode, then just drop a button from the toolbox onto the web page.
Say, like this:
Now, double click on the button, and we are jumped to code behind.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Library.aspx");
}
So, we put for the code to jump to the web page Library.aspx
We get this then:
And now, when I click on that button, I am jumped to the web page called Library.aspx - we should see this (assuming the web page Library.aspx exists).

OnTextChanged event doesn't fire on CKEditor control in ASP.NET

I have a checkbox, a button, and a CKEditor control (v3.6.1) that I've added to an existing asp.net webform page. Clicking the button saves the status of the checkbox and the contents of the CKEditor to the database and displays a saved successfully message. If the user modifies either one, the message should disappear. Well, the OnTextChanged event isn't firing on the CKEditor so that the label displaying the message can be hidden. I have tried doing this with javascript using the onkeypress event. I wrapped the CKEditor in a tag and put the onkeypress="..." on that with no luck. I even used jQuery to attach a function to the OnTextChanged (tried OnChanged too) event on document ready with no luck. This is driving me crazy as to why this simple thing won't work and it's the only thing holding me up from completing my project (at least going to the next phase). Can someone please help me with this as to why this isn't working. Code pertinent to this issue is pasted below:
.aspx
<tr>
<td>
<CKEditor:CKEditorControl runat="server" ID="txtClientProtocols" name="txtClientProtocols" Width="1000" Height="370" EnterMode="P"
ResizeEnabled="false" AutoPostBack="True" OnTextChanged="txtClientProtocols_TextChanged"></CKEditor:CKEditorControl>
</td>
</tr>
.aspx.cs
protected void txtClientProtocols_TextChanged(object sender, EventArgs e)
{
lblSuccess.Style["visibility"] = "hidden";
}
I did some research but haven't found anything that stood out as a solution. Thanks in advance for any help.
Following the recent CKEditor 3.6.2 release we would like to announce
the availability of our integrated version for ASP.NET. The ASP.NET
control was updated to the latest CKEditor version and contains all
the bug fixes and new features introduced in CKEditor 3.6.2, including
initial support for iOS5 and some API additions.
Apart from the changes included in the editor, some new features are
offered exclusively for the ASP.NET control: the OnTextChanged event
is now fired and the AutoPostBack property is available.
The scripts registration has been moved from OnLoad to OnPreRender, so
setting configuration in the code should now be always working. Issues
with Ajax postback should be also gone.
What's new ASP.NET
You should upgrade your version.

Display/hide control in Webpart based on edit/browse mode

I have a Visual Studio project in which I have created a Visual Webpart. In the user control I have a panel which I want to display in edit mode and hide in browse mode.
ASP.NET code snippet:
<asp:panel runat="server" ID="myControl">
C# code snippet in user control code behind:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(this.Page);
if (wpm.DisplayMode == WebPartManager.BrowseDisplayMode)
{
myControl.Attributes.Add("style", "display: none");
}
else if (wpm.DisplayMode == WebPartManager.EditDisplayMode)
{
myControl.Attributes.Add("style", "display: block");
}
}
This works, but if I have two same webparts on same page and put one webpart is edit mode it shows the panel in both webparts. It seems the OnPreRender event code runs for both webparts on page.
I even tried writing code as this.myControl.Attributes.Add("style", "display: block"); but it still didn't work.
I want the OnPreRender code to run only on its webpart and not modify the other webaprt on page. How can I resolve this? Is there any better (or preferred) way to do it?
NOTE: I need to use display: none because the panel would be accessed via JavaScript.
PS: This is a cross post from here as I did not get any satisfactory answers.
I do the same on the page load, and it works for me just fine .. (page has about 10 WP and only 1 behaves differently in the edit mode.)
Maybe what you mean is that you have 2 SAME webparts on the page? Then I guess both webparts will behave equally because WebPartManager.DisplayMode returns you the mode of the page, not the webpart. (see msdn).

ASP.NET and C# Redirect

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.

error CS0103: The name 'txtReferralCode' does not exist in the current context

I'm about ready to pull my hair out over this. I'm working on an ASP.NET 2.0 website in VS2010 and I'm getting the error you see in the title. The error only appears when I attempt to publish the website. If I simply right click the aspx file that it's in and click "View in Browser" it works perfectly fine. It also works fine if I run the file in debug mode from VS2010. There are other asp controls in the code that work perfectly fine, but for whatever reason, the one I've added has a problem.
Here's some of the relevant code:
c#:
public partial class ApplicationScreen1Hold : System.Web.UI.Page
{
....
protected void Page_Load(object sender, EventArgs e)
{
....
if (Request.QueryString["SID"] != null) //this is existing code
{
hdnSID.Value = Request.QueryString["SID"].ToString().Trim();
}
if (Request.QueryString["RID"] != null) //this is my new code
{
txtReferralCode.Text = Request.QueryString["RID"];
}
....
}
}
html:
<td style="padding-left:25px">
<label>Referral Code
<asp:TextBox ID="txtReferralCode" runat="server" MaxLength="8"></asp:TextBox>
</label>
</td>
In the c# code, I left in the line above to show how one of the other inputs in the same form is accessed with no issues. The text box control in the html I had copies from another text box on the page and changed the id and removed the class and onkeyup event as they weren't needed.
Is it possible I need to define the text box and I've just not found the where it does it for other controls or am I likely missing something else?
I've looked at the other questions which have referenced this error code but none of them have been able to help me.
Delete designer file associated with your *.aspx file. Right click *.aspx file and click "convert to web application". It will create a designer file thats *.aspx.designer.cs and this file must include all the controls you used in your .aspx file.
Make sure you use right namepsace thats *.aspx.designer.cs and *.aspx.cs controls are in the same namespace..

Categories

Resources