Thursday, March 29, 2012
Set connection string of table adapter dynamically
I am stucked with the following problem and hope you can help me :
- My ASP.NET 2.0 application has one master database .
- This master database has a Databases table with list of children
databases .
- All children databases have the same schema ( only the data is
different ) .
My application connects to the Master database first (
connection String of this database should be read from the C:\WINDOWS
\XXX.INI file).
Login web page will present drop-down list of sub-databases ( which
will be
retrieved from the Master database ) and then will connect to
specified sub-database and will display data
from this database in a GridView .
I would like to be able to bind this GridView to the Data Source
Objects , to edit all columns during design time , and to set the
connection string of corresponding table adapter programmatically
during run-time .
How can I do this ?
I found several references to the connection string ( for example ,
via appSettings) , but I got an error message that this is read only
parameter .
Please advice .
Thanks in advance for your help ,
Orit Chanukov .Keep it in a session variable.
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Orit" <oritc123@.gmail.com> wrote in message
news:1183138531.120152.59480@.a26g2000pre.googlegroups.com...
> Hello .
> I am stucked with the following problem and hope you can help me :
> - My ASP.NET 2.0 application has one master database .
> - This master database has a Databases table with list of children
> databases .
> - All children databases have the same schema ( only the data is
> different ) .
> My application connects to the Master database first (
> connection String of this database should be read from the C:\WINDOWS
> \XXX.INI file).
> Login web page will present drop-down list of sub-databases ( which
> will be
> retrieved from the Master database ) and then will connect to
> specified sub-database and will display data
> from this database in a GridView .
> I would like to be able to bind this GridView to the Data Source
> Objects , to edit all columns during design time , and to set the
> connection string of corresponding table adapter programmatically
> during run-time .
> How can I do this ?
> I found several references to the connection string ( for example ,
> via appSettings) , but I got an error message that this is read only
> parameter .
> Please advice .
> Thanks in advance for your help ,
> Orit Chanukov .
>
Set connection string of table adapter dynamically
I am stucked with the following problem and hope you can help me :
-My ASP.NET 2.0 application has one master database .
-This master database has a Databases table with list of children
databases .
-All children databases have the same schema ( only the data is
different ) .
My application connects to the Master database first (
connection String of this database should be read from the C:\WINDOWS
\XXX.INI file).
Login web page will present drop-down list of sub-databases ( which
will be
retrieved from the Master database ) and then will connect to
specified sub-database and will display data
from this database in a GridView .
I would like to be able to bind this GridView to the Data Source
Objects , to edit all columns during design time , and to set the
connection string of corresponding table adapter programmatically
during run-time .
How can I do this ?
I found several references to the connection string ( for example ,
via appSettings) , but I got an error message that this is read only
parameter .
Please advice .
Thanks in advance for your help ,
Orit Chanukov .Keep it in a session variable.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Orit" <oritc123@.gmail.comwrote in message
news:1183138531.120152.59480@.a26g2000pre.googlegro ups.com...
Quote:
Originally Posted by
Hello .
>
I am stucked with the following problem and hope you can help me :
>
- My ASP.NET 2.0 application has one master database .
- This master database has a Databases table with list of children
databases .
- All children databases have the same schema ( only the data is
different ) .
My application connects to the Master database first (
connection String of this database should be read from the C:\WINDOWS
\XXX.INI file).
Login web page will present drop-down list of sub-databases ( which
will be
retrieved from the Master database ) and then will connect to
specified sub-database and will display data
from this database in a GridView .
I would like to be able to bind this GridView to the Data Source
Objects , to edit all columns during design time , and to set the
connection string of corresponding table adapter programmatically
during run-time .
How can I do this ?
I found several references to the connection string ( for example ,
via appSettings) , but I got an error message that this is read only
parameter .
Please advice .
Thanks in advance for your help ,
Orit Chanukov .
>
Saturday, March 24, 2012
Set Focus to control
I have a content page (I am using a Master Page) that has a control
"ddlRequestType".
In my code behind, I am using the following to create an image and assign
JavaScript to it that will set the focus to the control "ddlRequestType":
If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
strValidateText &= _
"<tr>" & _
"<td width=200><div align=left>Request Type</div></td>" & _
"<td width=400><div align=left><A HREF=#
ONCLICK=ddlRequestType.focus()>" & _
"<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
"</div></td>" & _
"</tr>"
strValidateForm = "Validation Error"
End If
However, when I click on the image, I get the following error:
ddlRequestType is undefined.
Any help with this would be appreciated.
Thanks in advance,
sck10Hi,
Try:
document.getElementById('ddlRequestType').focus(); or
Form1.getElementById('ddlRequestType').focus();
Good luck! Ken.
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"sck10" <sck10@.online.nospam> wrote in message
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
>
>
I suggest you to don't use direct id or name for referencing javascript
object, try this:
HREF="java script:document.getElementById('ddlRequestType').focus()"
However i tink is better don't use string for create controls, try add
controls using TableCell,TableRow,ImageButton.
This is a simple example:
Dim tempRow as new TableRow()
Dim tempCell as new TableCell()
Dim myButton as new ImageButton
'Assign properties to rows and cell
myButton.attributes("onclick")="document.getElementById('ddlRequestType').fo
cus()"
tempCell.Controls.Add(myButton )
tempRow.Cells.Add(tempCell)
'add your row to your table rows
"sck10" <sck10@.online.nospam> ha scritto nel messaggio
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
>
>
Set Focus to control
I have a content page (I am using a Master Page) that has a control
"ddlRequestType".
In my code behind, I am using the following to create an image and assign
JavaScript to it that will set the focus to the control "ddlRequestType":
If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
strValidateText &= _
"<tr>" & _
"<td width=200><div align=left>Request Type</div></td>" & _
"<td width=400><div align=left><A HREF=#
ONCLICK=ddlRequestType.focus()>" & _
"<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
"</div></td>" & _
"</tr>"
strValidateForm = "Validation Error"
End If
However, when I click on the image, I get the following error:
ddlRequestType is undefined.
Any help with this would be appreciated.
--
Thanks in advance,
sck10Hi,
Try:
document.getElementById('ddlRequestType').focus(); or
Form1.getElementById('ddlRequestType').focus();
Good luck! Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"sck10" <sck10@.online.nospam> wrote in message
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
I suggest you to don't use direct id or name for referencing javascript
object, try this:
HREF="javascript:document.getElementById('ddlRequestType ').focus()"
However i tink is better don't use string for create controls, try add
controls using TableCell,TableRow,ImageButton.
This is a simple example:
Dim tempRow as new TableRow()
Dim tempCell as new TableCell()
Dim myButton as new ImageButton
'Assign properties to rows and cell
myButton.attributes("onclick")="document.getElementById('ddlRequestType').focus()"
tempCell.Controls.Add(myButton )
tempRow.Cells.Add(tempCell)
'add your row to your table rows
"sck10" <sck10@.online.nospam> ha scritto nel messaggio
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
Tuesday, March 13, 2012
Set properties on masterpage declaratively
Hi, is it possible to do this?
So you'd set a property on the master page in the aspx.
If by declaratively you mean programmatically, yes you can. Take a look at my example
I created a MasterPage, called BasePage.master, and added the following code to its code-behind:
public partialclass BasePage: System.Web.UI.MasterPage{private int magicNumber;public int MagicNumber {get {return magicNumber; }set { magicNumber =value; } }protected void Page_Load(object sender, EventArgs e) { }} Then I created a new Web Form (.aspx) page, called Test.aspx, and picked Base.master to be its MasterPage. I also added the following line to .aspx page:
<%@. MasterType VirtualPath="~/BasePage.master" %>
Using the MasterType directive allows the .aspx page to access the public properties and fields of the MasterPage via the Master property. The following code is from the code-behind of Test.aspx, take a look:
public partialclass Test : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) { Master.MagicNumber = 2007; }} Hope this helps.
Hi there, I appreciate your effort but since when has doing something declaratively ever meant writing code in a code behind file?? I mean, isn't the whole point of the word 'declarative' to indicate the absence of code?
Hi,
Your original question wasn't clear, as in you didn't say whether or not you had created the property on the Master page or not. Don't scold someone for trying to help you!
If you just need to set an existing property on the master page declaratively, then use the following code (for a string property):
<%Page.Master.MyProperty = "MyValue"%>
Of course though, if the property doesn't already exist on the Master Page, then youMUST write code to create it! For this, refer to the above post for instructions.
Rich
Yes my question was not that clear.
<%Page.Master.MyProperty = "MyValue"%>
The trouble with this is that its a render block so its not going to be set until the end of the page life cycle. I want to set the value of properties on the master page as if the master page was a user control contained by the page and the assignments are within the user control's tag.
Cheers, WT.
Hi,
Now I see what you mean! I don't think there is a way to do this directly. You are gonna have to write some code initially, but you should be able to reuse it on all pages using the same Master Page. The way I would do it would be to create a User Control and:
Expose a public property on the User Control, taking the value of the property you wish to set.