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).
Related
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).
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".
I had a .Net 1.1 Webapplication which I have converted to the .Net 3.5 and published on the Windows Server 2012. There is a grid in a page where I need to delete a records with the cross button in the grid. But when I try to delete it shows the following error in the Chrome Console
GET
http://10.72.10.225/Models/SEIIAG/WebResource.axd?d=3IplHgLpPO4L8SEYBdyuKR9…fWWwa68LbCK6T7EgwTmR_WdnTJJbBQZJoJJGdKMX0cZCVl9eahgU1&t=635161970660000000
500 (Internal Server Error)
Uncaught ReferenceError: WebForm_DoPostBackWithOptions is not defined
Workaround 1:
In case the page where the problem is observed is based on .master page Sitefinity template.
Add the GetPostBackEventReference manually to the .master page in the OnPreRender event handler. In order to do that you will need to add a code-behind to the master page.
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
var control = this.Controls[0];
this.Page.ClientScript.GetPostBackEventReference(control, string.Empty);
}
Workaround 2:
In case the page or page template uses asp:LinkButton controls change them to asp:Button controls.
Taken from Here
Got the solution
Go to IIS
Select your Virtual Directory
Select Handler Mappings
Double Click on that
Select *.axd and click Edit button
Change the value of executable section to
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
Click Ok
I have a visual web part (a simple form) with RequiredFieldValidators. But a problem has occured since the field validators block editing of the page. When i press Edit Page in Sharepoint it starts to load then the validators fire and the javascript is stopped.
I found a solution but i cant get it to work.
Like this
public override void CreateChildControls()
{
if(SPContext.Current.FormContext.FormMode == SPControlMode.Edit)
((UserControl)_ctl).EnableValidators(false);
((UserControl)_ctl).EnableValidators(true);
}
//But the _ctl does not exit i only have
Control control = Page.LoadControl(_ascxPath);
A litte advice would help this sharepoint noob a great deal.
The form is just Labels, Inputs, a button, updatepanel and requiredFieldValidators
Can you not just set the ValidationGroup for the validators and button? Like this: http://msdn.microsoft.com/en-us/library/ms227424.aspx
The validators should only fire when the button is pressed.
There is something wrong with your configuration - I tested this configuration and the required field validators definitely don't block editing on the page. Do you want to post your page and your code behind? Might help to troubleshoot the problem.
This is not browser specific - the behavior exists in Firefox and IE. The RadControl is being used within a User Control in a SiteFinity site.
Very little customization has been done to the control.
<telerik:RadDateTimePicker ID="RadDateTimePicker1" runat="server"
MinDate="2010/1/1" Width="250px">
<ClientEvents></ClientEvents>
<TimeView starttime="08:00:00" endtime="20:00:00"
interval="02:00:00"></TimeView>
<DateInput runat="server" ID="DateInput"></DateInput>
</telerik:RadDateTimePicker>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadDateTimePicker1.MinDate = DateTime.Now;
}
}
[Disclaimer, I work for Telerik]
I don't specifically know what the issue is, however here are some general troubleshooting steps that might help unearth the issue:
Check for Javacript errors - (Firefox's Error Console would do it)
Isolate the RadDateTimePicker control from Sitefinity - (Create a normal ASPX page and place the RadDateTimePicker control on this page. Does it work in this environment?)
Check for stylesheet issues using Firebug and/or remove stylesheets (backup first).
In general, keep simplifying until it starts working then re-add complexity until it breaks again. This normally tells me where the problem is.
Alternately, you could send your project/code to Telerik support. Best of luck.
Can you try changing MinDate to use:
RadDateTimePicker1.MinDate = System.DateTime.Parse(String.Format("{0}/{1}/{2}", System.DateTime.Now.Month, System.DateTime.Now.Day, System.DateTime.Now.Year - 1))
And tell me if the behavior changes.
Also, is the new highlight being shown as well, or is it stuck on the old highlighting completely?