|
I have an application where the user can select to which databse he want to be connected. In my masterpage i have a function that is searching all the Sqldatasource in a page and change all the connectionString to connect the user to the selected database. This function is work fine excempt if the SQLdatasource is inside a Formview TAG this is not working at all. I know for sure that my function is able to found the SQLdatasource inside the formview and change the connectionString but when the page is loaded the SqlSource inside my formview is using the default connectionString.
I've tried in the pageLoad of my page to change the connectionString of one of the SqlDatasource inside a formview and i still have the same problem. I've put a response.write in the pageLoad and i can see that the ConnectionString was changed but when i put another Reponse.write in the databound event i can see the the SqlDatasource still use the default ConnectionString and not the one in the pageload. Did i forget to do something. All i want is to dynamically changed the connectionString of the SqlDataSource inside my formview.
I just want to know how to change dynamically a SQLDatasource inside a formview.
Thanks !
|
|
|
|
|
Because the SqlDataSource control is placed inside the FormView (in other words it's a child of the FormView), so when you try to access the SqlDataSource, that causes the FormView's control hierarchy to be built, and this always happens before you repalce the default connection string, so it uses the default value. In this case, you may think of persisting the connection string in a central place so that once you change it that will affect all other places instead of walking all the controls to change one by one like you are doing.
|
|
|
|
|
Thanks for your answer ! I already have a class with a function that return my current connection string. Is there a way for my SQLDatasource to use this function ? Our website have over 100+ pages. so when they decided to allow users to change database, instead of changing all our connection string i've thought of adding a procdedure to search for all datasource in a page and then change their connection string.
|
|
|
|
|
My point is that instead of searching all the datasources on the web page to update their ConnectionString property, we only need to update the connection string in a central place and all the datasource controls using this place will benefit this change. Below is the sample code to demonstrate what I mean:
public class ExSqlDataSource : SqlDataSource
{
public override string ConnectionString
{
get
{
return base.ConnectionString;
}
set
{
string conString = HttpContext.Current.Items["MyConnecionString"] as string;
if (string.IsNullOrEmpty(conString))
conString = value;
base.ConnectionString = conString;
}
}
}
In the example above, I use the HttpContext.Current.Items to store the connection string (you can use whatever you want), this custom sqldatasource control can be used on the web page in lieu of the built-in sqldatasource control as below:
<cc1:ExSqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="..."></cc1:ExSqlDataSource>
At runtime, the datasource control by default uses the connection string stored in the ConnectionStrings section of the web.config file under the key NorthwindConnectionString . If I want to dynamically replace this connection string, I simply set it in the HttpContext.Current.Items["MyConnecionString"] item in the web page:
public partial class Default_ : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
HttpContext.Current.Items["MyConnecionString"] = "new connect string goes here";
}
}
So all custom datasource controls declared in the web page will benefit this new connection string without requiring you to set their ConnectionString property.
In addition, there is also another extention point that you can use to change the default connection string. That is you can build your own expression builder and you can use your own expression to set the ConnectionString property of the datasource control. With this option, you can intervene the way the ASP.NET sets the ConnectionString property of the datasource control. For more details, you can check out the article[^].
|
|
|
|
|
Thanks a lot !!! I'll see what i can do. The problem is that our application has over 200 page. So when they ask us to allow users to be able to select a database (which was impossible before) i've searched a solution where i will not have to change all the pages. That's why i added a function in our masterpage to search for all the datasource and then update the connectionString.
Now i realize that it was not a good idea.
Thanks again !
|
|
|
|
|
I have a wizard control in my .net 2.0 page. I ran into a problem in which clicking on "Previous Button" will result in an error message: The command 'MovePrevious' is not valid for the previous step, make sure the step type is not changed between postbacks.
Also clicking on the "Finish Button" will result in an error message: The command 'MoveComplete' is not valid for the previous step, make sure the step type is not changed between postbacks.
However, the "Next Button" works without any problem.
My first wizard page has StepType="Start"
Second wizard page has StepType="finish"
Last wizard page has StepType="Complete"
I have not done any fancy stuff to the control, but I cannot get the button click to work.
Rookie Programmer
|
|
|
|
|
You may want to debug your code and have a look at some properties of the Wizard control like ActiveStepIndex, WizardSteps. Btw, how do you define the wizard control? declaratively or dynamically?
|
|
|
|
|
Hi, How I can set direction of SiteMapPath to "right to left" in ASPNET2?
Thanks.
|
|
|
|
|
|
Thank you very much minhpc_bk.
|
|
|
|
|
Hello,
I am loading a xml file as follows:
docXML.Load(server.MapPath("MyFile.XML"))
Instead of using server.MapPath("MyFile.XML") to select the XML file to use I want to use the same file which is defined in the sitemap provider "SiteMapProvider".
<providers>
<clear/>
<add
name = "SiteMapProvider"
siteMapFile = "~/MyFile.sitemap"
type = "System.Web.XmlSiteMapProvider" />
Is this possible? How can I do this?
Thanks,
Miguel
|
|
|
|
|
|
i`ve used the following code while uploading a .csv file
if(pFileObject.PostedFile.ContentType.ToString() == "application/octet-stream")<br />
{<br />
throw new Exception("Please close the file you want to upload and then try again.");<br />
}
it works fine in my machine, but in other machines it works just opposite, i mean when the file is open it gives the error message but when it is closed it uploads successfully, but for other machines it works just opposite, and in other machines when uploading the .csv file it always returns content type as "application/octet-stream".
good suggestions are welcome
|
|
|
|
|
Hi,
My ASP.NET application is hosted on Windows 2003 Standard Server with IIS6.0. My
application dynamically converts the autocad files to PDF when user request it, For this i
am using third party command line tool which accept input file path and output file path and
i am calling this exe using [B][I]Shell()[/I][/B] method. Evetything is working fine on
development machine which is windows 2000 pro. But when i run the same on server seems like
thigs not working,Is it related to any security settings of IIS.
(I also set the application Execute permission to Script and Executable but no luck....
:ehh: )
If you can provide any thread it would be help full.
Regards,
Ritesh N. Jain
|
|
|
|
|
Hi there,
How do you run the executable from the ASP.NET? You are using the Process class? You might want to check out this document[^].
|
|
|
|
|
Hi,
thanks for reply.I tried with both Process class as well as with Shell() but no luck, when i call the process it runnning in task manager but generate no o/p file.......
Regards,
Ritesh
|
|
|
|
|
You might want to check the account under which the spawned process runs in the Task Manager to see if it has enough permission to do the task.
Another option you can try is that you can implement a window service which is responsible for running the third application. The ASP.NET application can use the .Net Remoting to simply send a request to the service to have it run the application.
|
|
|
|
|
hi,
the third party is running under local service account (same as w3w ) and i set full control for this account for exe as well as for web app, i don't have much idea about remoting but i will try to it,
Thankx,
Ritesh
|
|
|
|
|
Hi I am having trouble with an asp.net panel on my c# project when I do a postback to save certain info on the page my list of 16 dropdown lists in the panel all lose their selected values so I am just wondering if anyone knows why this is happening or how to prevent it from happening thanks in advance
Tim
|
|
|
|
|
did you fill ddls inside !Page.IsPostBack ???
|
|
|
|
|
yes i did that but i have actually just realised that i was wrong with what i thought was the problem as the ddls dont lose their values they are filled a second time and so are set back to the first ListItem. so my problem now is how do stop an event from bein fired when i save the first values.
the page has a User Control on it and i need to fire an event when a item is selected on a ddl so i attached an event handler to the ddl
//*** attach handler to ddl match
SelectSeasonCountryCompTeamMatch1.MatchChanged += new System.EventHandler(this.match_SelectionChanged);
but when i press the save button this function match_SelectionChanged is executed again and the values they are filled a second time. i wud apreciate any advice on this problem thanks
|
|
|
|
|
is it possible setting read/write permissions on System.Windows.Forms.Clipboard for reading/writing data on clipboard
|
|
|
|
|
|
How to get a selected value from Grid view and what are the properties i have to set in the aspx page for the checkbox field
-
|
|
|
|
|
you can get many examples related to gidview
Here[^].
Best Regards,
Apurva Kaushal
|
|
|
|