|
This is what I did and it works:
You have a hidden control calls vertscrollpossition and a panel called panel_contents.
This is the code behind:
private void SetScrollPosition(){
string script;
ClientScriptManager CSManager = Page.ClientScript;
if(!CSManager.IsOnSubmitStatementRegistered(this.GetType(),"SaveScrollPosition")){
script = "var HiddenField = document.getElementById('" + vertscrollposition.ClientID + "');\n\r";
script += "var ScrollElement = document.getElementById('" + panel_contents.ClientID + "');\n\r";
script += "HiddenField.value = ScrollElement.scrollTop;\n\r";
CSManager.RegisterOnSubmitStatement(this.GetType(), "SaveScrollPosition",script);
}
if(!CSManager.IsStartupScriptRegistered(this.GetType(),"RetrieveScrollPosition")){
script = "var HiddenField = document.getElementById('" + vertscrollposition.ClientID + "');\n\r";
script += "var ScrollElement = document.getElementById('" + panel_contents.ClientID + "');\n\r";
script += "if(HiddenField.value != '')\n\r";
script += "{\n\r";
script += "ScrollElement.scrollTop = HiddenField.value;\n\r";
script += "}\n\r";
CSManager.RegisterStartupScript(this.GetType(), "RetrieveScrollPosition",script, true);
}
}
This is the aspx code:
<asp:Panel ID="panel_contents" Height="175" Width="800" runat="server" ScrollBars="Vertical" ViewStateMode="Enabled" EnableViewState="True">
</asp:Panel>
<asp:HiddenField ID="vertscrollposition" runat="server" />
V.
|
|
|
|
|
Have you tried setting MaintainScrollPositionOnPostback="true" on your page? If that works, that would be the easiest to do.
|
|
|
|
|
Hi,
I am trying to connect to mySql using C# but getting this error:
Quote: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I have added the port thinking it could solve the issue! but still the same.. here is my connection string:
<add name="SQLdb" connectionString="server=192.168.0.1;port=3306;User Id=root;password=Mxjxaxax0x1;Persist Security Info=True;database=cure"
providerName="MySql.Data.MySqlClient" />
please help...
|
|
|
|
|
The answer is bound to be here
|
|
|
|
|
Thanks BUT
now this is my connection in the App.config:
<add name="SQLdb"connectionString="server=192.168.0.1;port=3306;Uid=root;Pwd=xxxxxxxxx;database=cure;" providerName="MySql.Data.MySqlClient" />
but I am still getting:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
just one notes:
The same code is working if I run the application on the server itself (using IP not localhost)
|
|
|
|
|
What happens if you try to connect to the database using a standard MySQL client? It almost looks like a firewall may be blocking your connection.
|
|
|
|
|
it works when I connect using mySQL client
but the good news..
I figured out the problem...
I just address connection timeout=120
it seems like it's taking time to connect!
anyhow..
thanks...
|
|
|
|
|
Hi,
can anyone guide plz..
I want to save the sqlConnection parameters in an encrypted file so the WinForm application will read the host, database, user name, and password from that file.. The file will be distributed with the application..
Regards,
jkassim
|
|
|
|
|
Just store it in your app.config file in the ConnectionStrings section. You can then encrypt this section, using techniques discussed here[^].
|
|
|
|
|
You beat me to it
(I refreshed the page before submitting my answer)
|
|
|
|
|
i get an issue with changing datagridviewbutton text per row
read alot but no suffient answer
can anybody help me ?
thanks
|
|
|
|
|
Mr.Kode wrote: i get an issue
But you don't want to tell us what it is?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
hi
I don't know haw can I open resources declared in other files in the main xaml.
I created another xaml file name PageOption where I declare all the elements I need in the page options page.
How do I open this page when I click on the Options menu item.
I am interested in a xaml solution, or just how to open the page in the event onClickOptionMenu handler function.
incomplete xaml:
<Window x:Class="georgeAlpha.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="320" Width="625">
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="DockPanel Sample">
<DockPanel LastChildFill="True">
<Border Height="30" BorderBrush="Black" BorderThickness="1" DockPanel.Dock="Top">
<Menu Name="menu1">
<MenuItem Header="_File" HorizontalAlignment="Left">
</MenuItem>
<MenuItem Header="_SaveAs" />
<MenuItem Header="_Options" HorizontalAlignment="Left">
</MenuItem>
modified 23-Jan-12 11:47am.
|
|
|
|
|
Typically your View (XAML) will inform a ViewModel, via the click event, to invoke the Options object.
If you think that's bleak and cheerless, too bad. Reality doesn't owe us comfort. - Richard Dawkins
|
|
|
|
|
I put a Resource dictionary, declare there the page
and in MenuItem_Click showing the window.
It works..but I am wondering how to do this directly in XAML on click event.
<MenuItem Header="_Options" HorizontalAlignment="Left" Click="MenuItem_Click">
<MenuItem.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="myDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</MenuItem.Resources>
</MenuItem>
created a myDictionary.xaml file
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window x:Key="pageOptions" Name="Test">
</Window>
</ResourceDictionary>
|
|
|
|
|
Hi
I need to run the content of the batch file from C#. How to do that?
Content of the batch file:
echo off
\\server-name\directory\PsExec.exe -u domain\user-id -p ****** -d -e cmd.exe /c \\server-name\directory\file.exe
I require this to run a software with admin id in system where user does'nt have admin access.
Please post the complete code with all the namespace details since I'm a beginner.
Note: i don't want to have a batch file, i want to write everything in C#.
|
|
|
|
|
You should use the Process.Start()[^] method.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
This site is not a 'free code supermarket'.
You have your requirements, then start reading/coding ; and come back here when you have a specific question rather than a demand for ready code...
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
Chose one forum and stick to it[^].
Posting to multiple forums annoys the people that you want to get help from, so it's not a good idea.
Ciao,
luker
|
|
|
|
|
I have a group of classes (following strategy pattern) in my project. In the main function, I receive an enum value from the server and based on that I create an object of the base class type.
I am using switch/case statement to achieve this. I read somewhere that the Open/Closed principle does not allow opening a function to add a new case statement whenever a new class is added.
I am thinking of using a Activator.CreateInstance(). Is there any drawback to it.
Is there any other way to create an object from the enum type?
Adding example below even though it is not a full fledged Strategy pattern
abstract public class Mammal
{
public abstract void MakeSound()
}
class Cat:Mammal
{
public override void MakeSound()
{
Console.WriteLine("Meow");
}
}
class Dog:Mammal
{
public override void MakeSound()
{
Console.WriteLine("Bow");
}
}
Main()
{
MammalTypes mammalType = RecieveValueFromServer();
Mammal mammalBase
switch(mammalType)
{
case MammalTypes.Cat:mammalBase = new Cat()
break;
case MammalTypes.Dog:mammalBase = new Dog()
break;
}
mammalBase.MakeSound()
}
|
|
|
|
|
If you qualify it with the namespace, you can use Reflection to create an object from it's string name:
string myType = "MyNamespace.MyClass";
Assembly asm = Assembly.GetExecutingAssembly();
Type t = asm.GetType(myType);
Object o = Activator.CreateInstance(t, null, null);
I would combine this with this tip: Human readable strings for enum elements[^] to replace the human readable bit with the full namespec on each enum element, and you are done.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thanks,
Is there any drawback if this method replaces
switch/case statements for determinging type at run time?
|
|
|
|
|
Speed probably - I haven't checked this specific case, but Reflection is never quick!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: Reflection is never quick
True, but often you can cache the results, I think this is one such situation.
|
|
|
|
|
OriginalGriff wrote: but Reflection is never quick!
That certainly requires qualification.
Regardless of whether one uses reflection or not the .Net code is still loaded via the same mechanism and called via the same mechanism.
So if there is a measurable difference then it will be due to the proxy nature of the reflection semantics. I would suspect that using an interface/base class would entirely eliminate that.
But even if not I would suppose that one is going to have a very unusual plugin hierarchy for the reflection call itself to have an significant (above noise level) impact on performance.
|
|
|
|